I have implemented a RecyclerView
and I have set it up to use CAB
. But how can I highlight the selected items? If a certain position I checked I stored in a SparseBooleanArray
.
My first thought was to store the specific View
containg all the elements in my ViewHolder
and then in onBindViewHolder
set the background somehow to: ?android:attr/activatedBackgroundIndicator
But how can I do that? Is that a useful approach?
Asked
Active
Viewed 8,290 times
7

Paul Woitaschek
- 6,717
- 5
- 33
- 52
-
1Was this ever resolved? – DragonJawad Dec 09 '14 at 22:58
2 Answers
2
I finally solved this by simply adding some minor things:
First of all, the items of the RecyclerView have to use this as background:
android:background="?android:attr/activatedBackgroundIndicator"
Then for the RecyclerView simply call: setSelected(true); on the indiviual views.

Paul Woitaschek
- 6,717
- 5
- 33
- 52
-
-
@Paul Woitaschek can you provide any code how you solved it please ? – Yasin Kaçmaz Jul 19 '16 at 18:18
1
If you want to change the View itself, you need to dispatch adapter.notifyItemChanged(position) and in return, recycler view will call onBind method where you can set the background.
If you don't need to update the view itself, I would suggest using an item decorator.

yigit
- 37,683
- 13
- 72
- 58
-
1What you mean with not need to update the view itself? How can I decorate a single item in a view with item decorator? And how can I set the background with android:attr/activatedBackgroundIndicator? – Paul Woitaschek Oct 25 '14 at 19:34