1

I put another RecyclerView B in a RecyclerView A. I set an OnClickListener into the ItemView in the Adapter of the outer RecyclerView A.

When I click anywhere on the ItemView in RecyclerView A, OnClickListener will work well but when I click RecyclerView B in ItemView, My OnClickListener does not work anymore. Does anyone know why it behaves like this?

Pranav P
  • 1,755
  • 19
  • 39
Jim
  • 33
  • 5

1 Answers1

0

The best way way to solve this problem is to give OnClickListener to adapter's main layout.

For eg:-

<RelativeLayout 
  android:layout_above="@+id/mainlayout"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  ............ //more layout.

 </RelativeLayout>

Then give OnClickListener in adapter..

holder.mainlayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Your code
        }
    });

This will work and solve your problem..