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
Select all / Deselect all / Inverse all
For Activity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_select_all) {
for(int i=0; i < lvDownload.getChildCount(); i++){
LinearLayout itemLayout = (LinearLayout)lvDownload.getChildAt(i);
CheckBox cb = (CheckBox)itemLayout.findViewById(R.id.cbFileDownload);
cb.setChecked(true);
}
return true;
} else if (id == R.id.action_deselect_all) {
for(int i=0; i < lvDownload.getChildCount(); i++){
LinearLayout itemLayout = (LinearLayout)lvDownload.getChildAt(i);
CheckBox cb = (CheckBox)itemLayout.findViewById(R.id.cbFileDownload);
cb.setChecked(false);
}
return true;
} else if (id == R.id.action_inverse_all) {
for(int i=0; i < lvDownload.getChildCount(); i++){
LinearLayout itemLayout = (LinearLayout)lvDownload.getChildAt(i);
CheckBox cb = (CheckBox)itemLayout.findViewById(R.id.cbFileDownload);
cb.setChecked(!cb.isChecked());
}
return true;
}
return super.onOptionsItemSelected(item);
}
lvDownload - ListView ID LinearLayout or RelativeLayout - see root in your item cbFileDownload - CheckBox ID see in your item
And Menu: