Skip to content Skip to sidebar Skip to footer

Highlighting Rows Of Cardview In Recyclerview

I am following the Big Nerd Ranch tutorial on RecyclerView tutorial on RecyclerView. I changed a few things and there. The problem I am facing is that when I click on the row; that

Solution 1:

So after tons of research, I finally found an answer. If you are using CardView + Big Nerd Ranch MultiSelector. When you highlight the CardView by clicking on it, only that particular card is visible and not the rest of the cards in the RecyclerView. It's because SwappingHolder works by swapping out the drawables of the top-level View. But CardView uses its own drawables, so it will not work if you use it as the top-level View.

CardView uses its own background. SwappingHolder needs to be able to replace that background to do its work.

One option would be to implement the SelectableHolder interface yourself, and choose how you want to display a selected item.

Another option is that we can make CardView child of a FrameLayout. Something like this: <FrameLayout ... > <CardView ... > </CardView> </FrameLayout>

I have summarised what's basically said here

Solution 2:

I invite you to check a library I wrote recently that implements multi-selection (drag&drop and swiping too, if you end up needing them). On one of the samples of the library there's also implemented selection by putting a drawable on top of the ViewHolder. However, the approach used is activating the drawable when the ActionMode starts, capturing click events on this drawable to toggle selection states, and then set the drawable visibility to GONE when the ActionMode exits.

Maybe by checking the source code you can find something of interest: https://github.com/MikiLoz92/FancyAdapters

Post a Comment for "Highlighting Rows Of Cardview In Recyclerview"