0

This code in onclick of the Button in Activity:

if(v.getId()==recomendationSelectAllFriends.getId()){
    recomendationAdapter.selectAll(resultEntities.size());
}

This method in Adapter:

public void selectAll(int size){
   // what should be written here?
}
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
  • https://stackoverflow.com/questions/4876083/correct-way-to-check-all-checkboxes-in-listview check this – AAA Aug 07 '17 at 09:19

2 Answers2

0
public void selectAll(int size){
   // what should be written here?

   for(DataEntity e: data) { //your list of data in the array
      e.isChecked(true)
   }
   notifyDataSetChanged();
}

where e.isChecked field is bounded to the checkbox of the card.

Angel Koh
  • 12,479
  • 7
  • 64
  • 91
0

Add a boolean variable in your model class and name it checked, write getters and setters for that variable.

Now, In your onBindViewHolder write

if(resultEntities.get(position).isChecked(){
    holder.yourCheckBoxName.setChecked(true);
    }else{
holder.yourCheckBoxName.setChecked(false);
}

In your function

public void selectAll(){

   for(ResultEntity e: resultEntities) { 
      e.setChecked(true)
   }
   notifyDataSetChanged();
}
Ashish Kumar
  • 374
  • 4
  • 11
  • Model layer should not know about the view layer. In your approach you are ignoring this rule – Araz Nov 23 '21 at 17:31