My Companies

Recycler View Item Click Listener

With the Android L release, RecyclerView has replaced ListView as the goto component for creating a view for providing window to a large data set. It promises lots of performance improvements over the standard list view.

To use the RecyclerView widget, you have to specify an adapter and a layout manager. To create an adapter, extend the RecyclerView.Adapter class. The details of the implementation depend on the specifics of your dataset and the type of views. For more information, see the guide.

An important point that the guide leaves out is about handling clicks on the recycler view items. There is no such thing as OnItemClickListener for RecyclerViews. Given that RecyclerView takes ListView a step further and doesn't have a concept of a row/column, but rather an arbitrarily laid out amount of children, they have delegated the onClick to each one of them, or to programmer implementation.

Here's how we can add a item click listener by implementing the RecyclerView.OnItemTouchListener to respond to only single tap events. This is just a
beginning and can ofcourse be extended to provide more complex gestures like long click etc.