Trying to activate CAB menu when clicking on MenuItem from ActionBar. Here is how I set the GridView for listening to Multi Choice. The multiModeChoiceListener is working fi
From your question I understand that you're trying to start the GridView
associated CAB from clicking one of the menu items. I don't know if you can do this(but I may be mistaken) as the MultiChoiceModeListener
expects an item to be checked to start. Depending on your layout and the overall appearance of the GridView
, I think you could have a dummy item(as an extra item in the adapter) at the end of the GridView
(with no content showing) and use setItemChecked(dummyItemPosition, true)
to start the GridView
CAB. Of course you'll need to have additional logic to take care of that extra item in your MultiChoiceModeListener
:
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
if (position == theDummyPosition)
return; // so we start the CAB but there aren't any items checked
}
int selectCount = gridView.getCheckedItemCount();
if (selectCount > 0) {
notify = true;
dataArray.add(position);
// if you select another item you'll have two selected items(because of the dummy item) so you need to take care of it
switch (selectCount) {
case 1:
mode.setSubtitle("One item added to favorites");
break;
default:
mode.setSubtitle("" + selectCount
+ " items added to favorites");
break;
}
}
}
The solution above is a hack, most likely it would be much easier to lose the MultiChoiceModeListener
and simply start an ActionMode
that you can manipulate for both situations.