user4292106 user4292106 - 3 months ago 11x
Android Question

Get the position of clicked item on Recycler View

I have implement a

and it works fine. I have an
which contains the data for the recycler view. The layout of each item is complicated. It contains two
. The framelayout1 contains an image and a text and the framelayout2 contains an image and four texts. When the user clicks on the framelayout1 I want to open the Activity1 and when the users clicks on the framelayout2 I want to open the Activity2. I have already search for the onClick in Recycler View and I have found very useful this. But how can I get the position of the arrayList in order to pass it via Intent in the activity1 or activity2?


Try getAdapterPosition() from inside the view holder so that you may get the adapter position of the click the user made.

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

   public ViewHolder(View itemView) {

   public void onClick(View v) {
       Toast.makeText(context, String.valueOf(getAdapterPosition()), Toast.LENGTH_SHORT).show();

For more in getAdapterPosition() follow this link