How can I select all checkboxes in recyclerView?
I try to do it like this:
in Adapter:
public void selectAll(){
Log.e("onClickSelectAll","yes");
isSelectedAll=true;
notifyDataSetChanged();
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
PersonDTO item = dataSet.get(position);
holder.tvName.setText(item.getName());
if (!isSelectedAll) holder.cbSelect.setSelected(false);
else holder.cbSelect.setSelected(true);}
In layout
Activity
I have a button
with onClickListener
:
private void onClickSelectAll(View view) {
getSelectPersonsAdapter().selectAll();
}
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