title: ListView: hide Contextual Action Bar
body: <p>I'm following the <a href="http://developer.android.com/guide/topics/ui/menus.html#CAB" rel="nofollow">official guide for using contextual action mode</a> like this: </p>
  
  <pre><code>    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
      listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
  
          @Override
          public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
          }
  
          @Override
          public boolean onCreateActionMode(ActionMode mode, Menu menu) {
              MenuInflater inflater = mode.getMenuInflater();
              inflater.inflate(R.menu.shelf_context, menu);
              return true;
          }
  
          @Override
          public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
              return true;
          }
  
          @Override
          public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
              // some processing...
              return true;
          }
  
          @Override
          public void onDestroyActionMode(ActionMode mode) {
          }
      });
  </code></pre>
  
  <p>My listView is inside a <code>Fragment</code> which is inside a <code>ViewPager</code>, so I want to hide the Contextual Action Bar when the fragment becomes invisible. But how do I do that? I call <code>listView.clearChoices()</code> to clear the selection, but the CAB is still visible:</p>
  
  <pre><code>@Override
  public void setUserVisibleHint(boolean isVisibleToUser) {
      super.setUserVisibleHint(isVisibleToUser);
      if (!isVisibleToUser) {
          listView.clearChoices(); // CAB is still visible.
      }
  }
  </code></pre>