#The Problem In the way of replacing ListViews with RecyclerView I hit this obstacle where there is no onItemClickListener in RecyclerView ??? And when googled, I found almost all the posts saying we have to implement this using the GestureDetector. And some of them had used interfaces which is what I too thought of using in the first place. But even they were so much confusing and complex to understand.
#Solution
- Interfaces (Donot worry if you never used one. But they are very simple concept) - CustomItemClickListener.java
- ViewHolder Adapter - ItemsListAdapter.java
- ViewHolder Item Class - ItemsListSingleItem.java
- The RecyclerView Itself - ItemsList (See Setting up the RecyclerView)
Consider for example you have a list of thumbnails and a title to be listed. I would do the following to keep stuff simple and working. :)
Checkout the sample project here
I like this solution. Its easy to keep it internal to the adapter if you don't need to bubble up to the activity for whatever reason.
This doesn't suffer from the undesirable delay of the gesture detect method. Unlike the clicklistener in the viewholder method, here you retain access to the adapter or activity.