I am using simple listView with simple_list_item_multiple_choice
I have added a checkbox and on its checked event want all list items to get selected
Call a method from a ListAdapter on a button click or onOptionsItemSelected(MenuItem item).
case R.id.selectAll:
listAdapterData.selectAll();
return true;
case R.id.unselectAll:
listAdapterData.unselectAll();
return true;
And then,
public class ListAdapterData extends BaseAdapter {
Context cntxts;
private LayoutInflater mInflater;
private ArrayList objects;
public SparseBooleanArray mSelectedItemsIds;
boolean[] checkBoxState;
boolean IsVisibleMain;
public ListAdapterData(Context context, ArrayList objAll, boolean IsVisible) {
mInflater = LayoutInflater.from(context);
this.cntxts = context;
this.objects = objAll;
this.mSelectedItemsIds = new SparseBooleanArray();
checkBoxState = new boolean[objects.size()];
this.IsVisibleMain = IsVisible;
}
public void selectAll() {
for (int i = 0; i < checkBoxState.length; i++) {
checkBoxState[i] = true;
}
notifyDataSetChanged();
}
public void unselectAll() {
for (int i = 0; i < checkBoxState.length; i++) {
checkBoxState[i] = false;
}
notifyDataSetChanged();
}
}