I was exploring RecyclerView
and I was surprised to see that RecyclerView
does not have onItemClickListener()
. Because RecyclerView
extends
android.view.ViewGroup
and ListView
extends
android.widget.AbsListView
. However I solved my problem by writing onClick
in my RecyclerView.Adapter
:
public static class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
public TextView txtViewTitle;
public ImageView imgViewIcon;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
txtViewTitle = (TextView) itemLayoutView.findViewById(R.id.item_title);
imgViewIcon = (ImageView) itemLayoutView.findViewById(R.id.item_icon);
}
@Override
public void onClick(View v) {
}
}
But still I want to know why Google removed onItemClickListener()
?
Is there a performance issue or something else?
Check this one in which I have implemented all the things with a proper way
RecyclerViewHolder Class
Adapter
The interface
I like this way and I'm using it
Inside
Put
And create this class anywhere you want it
I've read before that there is a better way but I like this way is easy and not complicated.
See my approach on this:
First declare an interface like this:
Then create the adapter:
And now let's see how to integrate this from a fragment:
Modified my comment...
> How RecyclerView is different from Listview?
One difference is that there is
LayoutManager
class with RecyclerView by which you can manage yourRecyclerView
like-Like for horizontal scrolling for RecyclerView-
How to put it all together example...
ViewHolder types