Trying to activate the CAB menu by clicking on MenuItem from the ActionBar. This is how I installed GridView to listen to Multi Choice. MultiModeChoiceListener works fine when I click on Any item in the GridView for a long time. It is working fine. Now I have a requirement to activate the CAB menu when you click on a menu item in the action bar. After pressing it, the CAB menu should indicate that 0 items have been selected. After that, he should let me select elements from the GridView with one click. How can I achieve this feature?
GridView Set Receiver:
gv.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); gv.setMultiChoiceModeListener(new MultiChoiceModeListener());
MultiChoiceModeListener.java
public class MultiChoiceModeListener implements GridView.MultiChoiceModeListener { public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.featured_multiselect, menu); MenuItem mi = menu.findItem(R.id.close); mi.setIcon(R.drawable.cancel); mode.setTitle("Select Items"); return true; } public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return true; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show(); if (item.getTitle().toString().equalsIgnoreCase("Close")) { mode.finish(); } return true; } public void onDestroyActionMode(ActionMode mode) { new ChangeNotifier().changeOnFavoriteStore = true; new AddFavorites().execute("add", device_id, dataArray); if (notify == true) { Toast.makeText(getApplicationContext(), "Selected items are added to Favorites", Toast.LENGTH_SHORT).show(); notify = false; } } public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { int selectCount = gridView.getCheckedItemCount(); if (selectCount > 0) { notify = true; dataArray.add(position); switch (selectCount) { case 1: mode.setSubtitle("One item added to favorites"); break; default: mode.setSubtitle("" + selectCount + " items added to favorites"); break; } } }
OnMenuItemClick Method:
public boolean onPrepareOptionsMenu(final Menu menu) { final MenuItem editItem = menu.findItem(R.id.editit); editItem.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) {
source share