#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
Your solution is perfect for Recyclerview click. But can you please let me know how can we handle individual item clicks ( 2 buttons inside the RecyclerView ) like the below
adapter = new ItemsListAdapter(getActivity(), data, new CustomItemClickListener() {
@OverRide
public void onItemClick(View v, int position) {
Log.d(TAG, "clicked position:" + position);
long postId = data.get(position).getID();
// which button clicked and separate action for each button
}
});