I have list of items inside of recyclerview, and they are multiple selectable.
I want to have select button to select all, and if selected deselect all. I didn\'t se
Maintaining a separate list or flag doesn't work for me, as the contents of my recycler view can change at any given moment, and calling notifyDataSetChanged() can be costly for large data sets. The solution I came up with doesn't use either, instead iterating over the recycler views children. For example, inside whatever function responds to your "select all action", iterate the child views like so:
RecyclerView rv = ...;
List selection = ...;
...
public void selectAll() {
int count = rv.getChildCount();
for (int i = 0; i < count; i++) {
View view = rv.getChildAt(i);
if (!view.isActivated()) {
view.setActivated(true);
selection.add(view);
}
}
}