title: Activate CAB menu when OnClickEvent happens in Android
body: <p>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 fine when I long press on Any item in the GridView. It is working fine. Now I have a requirement to activate the CAB menu when do press on a menu item in Action Bar. Once it is pressed, the CAB menu should read that 0 items are selected. After that it should allow me to select items from GridView on single clicks. How can I achieve this feature?</p>
  
  <p>GridView set listener:</p>
  
  <pre><code>gv.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); 
  gv.setMultiChoiceModeListener(new MultiChoiceModeListener());
  </code></pre>
  
  <p>MultiChoiceModeListener.java</p>
  
  <pre><code>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 &gt; 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;
          }
      } 
  
     }
  </code></pre>
  
  <p>OnMenuItemClick method:</p>
  
  <pre><code> public boolean onPrepareOptionsMenu(final Menu menu) {
  
      final MenuItem editItem = menu.findItem(R.id.editit);
  
      editItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
  
          @Override
          public boolean onMenuItemClick(MenuItem item) {
              //the CAB menu should be activated here. So that it reads that 0 items are selected in ActionBar
  
              return false;
          }
  
      });
  </code></pre>