Search code examples
androidandroid-recyclerviewonitemclick

Handle only one either Recycler view's item click or inside view click


By following Handle Button click inside a row in RecyclerView and Issue with CardView and OnClickListener in RecyclerView my code is working for both view i.e complete row and imageview inside row.

If imageview inside row is clicked then onclick of row item should not fired, but it happen following approach in given links

Like for ListView item if you give focusable="true" of view inside row then onItemClick is not fired, if view inside row is clicked (only onClick(View) is fired.

How to make it possible with Recycler view?


Solution

  • You may have better success using listeners so that you can "bubble up" those events to your Activity/Fragment. Then you should be able to keep things separate.

    Here is an example: https://guides.codepath.com/android/Using-the-RecyclerView#attaching-click-handlers-using-listeners

    I followed the tutorial to create one for click on the row, and then created another (on my own) to handle clicking on the button within the row.