Select all checkboxes in RecyclerView
You made a simple mistake here
if (!isSelectedAll) holder.select_item.setChecked(false);
else holder.select_item.setChecked(true);
change setSelected
into setChecked
thats it
for both Select All and Unselect All
activty
checkall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(checkall.isChecked()){
categoryAdapter.selectAll();
}
else {
categoryAdapter.unselectall();
}
}
});
in adapter
public void selectAll(){
isSelectedAll=true;
notifyDataSetChanged();
}
public void unselectall(){
isSelectedAll=false;
notifyDataSetChanged();
}
@Override
public void onBindViewHolder(@NonNull final MyviewHolder holder, int position) {
final CategoryListItems list = categoryListItems.get(position);
holder.text.setText(list.getName());
if (!isSelectedAll){
holder.checkbox.setChecked(false);
}
else holder.checkbox.setChecked(true);