I am implementing a custom recyclerview with switch for item selection. I have a "Select All" option at the right corner of App Bar (top bar). I want to allow user to use Select All option and also allow individual item selection in recyclerview.
I don't know how to implement individual selection along with Select All. When an item is deselected after using the select all option and when the list is scrolled the item gets selected automatically as the isSelectedAll flag is set true in onBindViewHolder method in the below code.
******SELECT ALL CLICK LISTENER IN ACTIVITY CLASS******
mBinding.imageViewActionSelect.setOnClickListener(v -> {
mAdapter.selectAll();
});
******ADAPTER CLASS******
public void selectAll() {
isSelectedAll = true;
notifyDataSetChanged();
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
if (isSelectedAll) {
holder.mSwitchView.setChecked(true);
}
else
holder.mSwitchView.setChecked(false);
}