I am developing a Material Design Navigation Drawer. I've created a new class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener
in it to handle the user's click on the list items. I use the class this way within the MainActivity
class' onCreate
method:
mRecyclerView.addOnItemTouchListener(
new RecyclerItemClickListener(this, mRecyclerView, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {// do whatever
if(position!=0){
setItemChecked(position, true);
setSelectable(true);
boolean isSelected = view.isSelected();
view.setActivated(isSelected);
selectItem(position);
}
}
@Override
public void onItemLongClick(View view, int position){
// ...
}
})
);
I based this code from this blog post: RecyclerView part 2 but it's not getting the job done, and to me it's not clear at all on how am I supposed to get it working.
I've also checked out this seemingly easy solution: Innodroid - Tracking Selected Item in RecyclerView (also quoted in this answer) but it's not clear on how I am supposed to derive my MyAdapter
class to the TrackSelectionAdapter
class.
What's the best way to highlight list items? I'm stuck.
Please help.
MyAdapter
class and then extended theCickListener
interface with the 2 methodsonItemClick
andonItemLongClick
and worked like a charm! – Arnone