Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ButterKnife OnItemClick with RecyclerView?

As onItemClick is no more in RecyclerView, does ButterKnife still able to handle its item clicks with @onItemClick or with @onClick annotations?

If not so, any work around to use that?

like image 258
Silly Questions Avatar asked Nov 06 '14 04:11

Silly Questions


People also ask

Where do you add the Android onClick attribute to make items in a RecyclerView respond to clicks?

Where do you add the android:onClick attribute to make items in a RecyclerView respond to clicks? In the layout file that displays the RecyclerView, add it to the element. Add it to the layout file for an item in the row.

What is viewType in onCreateViewHolder?

onCreateViewHolder(parent: ViewGroup, viewType: Int) Parent is the ViewGroup into which the new View will be added after it is bound to an adapter position and viewType is the type of the new View. This method will return a new ViewHolder that holds a View of the given view type.


1 Answers

My solution is to use @OnClick inside the ViewHolder. This is the only way to have a clue about which element of the "list item" has been clicked.

like image 116
Ivan Morgillo Avatar answered Oct 11 '22 10:10

Ivan Morgillo