Skip to content
Advertisement

How can I solve a problem with click on item in horizontal RecyclerView?

I have a horizontal recycler view. There are some buttons. I will provide my code below. So the problem is that when I click on a button, does not happen anything. It just thinks that I did not click to it. I have another recycler view, but vertical and the code is pretty similar, but the second one works. I am traying to find a mistake for ages. I really hope you can help me. Thank you.

in my main:

JavaScript

recyclerView class:

JavaScript

Advertisement

Answer

Change your ViewHolder code to attach the OnClickListener to the button and not the itemView.

JavaScript

In your ViewHolder, itemView is the root viewGroup of your layout R.layout.activity_recycler_view_adapter_countinent_list, a RecyclerView can listen to click events on the entire row using setOnItemClickListener.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement