How to apply setItemChecked (position, true) with RecyclerView in Android?

I am developing a navigation box for material design. I created a new class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener in it to process the user by clicking on the list items. I use the class this way in the MainActivity class' onCreate :

 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 on this code from this blog post: RecyclerView part 2 , but it doesn’t work, and I don’t understand it all about how I should make it work. I also tested this seemingly simple solution: Innodroid - Tracking the selected item in RecyclerView (also cited in this answer ), but it is unclear how I should output the MyAdapter class to the TrackSelectionAdapter class.

What is the best way to highlight list items? I am stuck.

Please, help.

+7
android android-listview material-design android-recyclerview
Apr 17 '15 at 9:46
source share
1 answer

I think I found the best tutorial on using RecyclerView with all the necessary functions and without libraries (single + multiselection, hightlight, ripple, click and delete in multiselection, etc.). At first glance, this is well explained.

Here it is β†’ http://enoent.fr/blog/2015/01/18/recyclerview-basics/

[EDIT] Finally, I found the time to try, and I even created my own more flexible, everyone can benefit from my improvements : https://github.com/davideas/FlexibleAdapter . In this link I will also explain how this works. Please remember to add it to your project.

+7
Apr 29 '15 at 17:45
source share



All Articles