I extend AbsListView.MultiChoiceModeListener for multi selection in ListView, I want to change the action menu dynamically (when more than one ListView item selected).
private class ModeCallback implements ListView.MultiChoiceModeListener {
//inflate menu
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.compose_multi_select_menu, menu);
}
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
//want to remove some menu here, but not work
if (getListView().getCheckedItemCount() > 1) {
MenuItem item = menu.getItem(5);
menu.removeItem();
}
}
}
I try to remove MenuItem in onPrepareActionMode(), but not work. Also tried mode.invalidate() in onItemCheckedStateChanged().
Actually, I find in onPrepareActionMode() the menu passed in have no MenuItem at all.
Anyone can help on this ?
You can modify menu in your onItemCheckedStateChanged() by showing or hiding items like this:
Menu menu = mode.getMenu();
menu.findItem(R.id.some_item_id).setVisible(false);
where mode is ActionMode passed to onItemCheckedStateChanged
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With