Select all checkboxes in RecyclerView

no news picture no news · Sep 5, 2016 · Viewed 15.2k times · Source

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();
    }

Answer

AMAN SINGH picture AMAN SINGH · Oct 13, 2016

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