title: Context Action Bar in Fragments
body: <p>does anyone have a tutorial to implement a CAB in fragment that uses support library v7 (appcomat_v7)?</p>
  
  <p>I cant find any plus the developer.android tutorial is ambiguous.</p>
  
  <p>Here is my code so far. I am doing a simple test program that as you select items in the list, the context action bar will appear that says stuff like you selected x items and bring up a delete button.</p>
  
  <p>I am trying to do this in a fragment is well so all code posted here is inside a fragment.</p>
  
  <p><strong>the context bar XML file</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:idk="http://schemas.android.com/apk/res-auto" &gt;
  
      &lt;item
          android:id="@+id/menu_delete"
          android:icon="@android:drawable/ic_menu_delete"
          android:orderInCategory="100"
          idk:showAsAction="ifRoom|withText"
          android:title="Delete"/&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p>This is the implementation of the ActionMode.Callback interface</p>
  
  <pre><code>private ActionMode.Callback mActionModeCallback = new ActionMode.Callback()
  {
  
      // Called when the user selects a contextual menu item
          @Override
          public boolean onActionItemClicked(ActionMode mode, MenuItem item) 
          {
              // TODO Auto-generated method stub
              switch(item.getItemId())
              {
              case R.id.menu_delete:
                  return true;
  
              }
  
              return false;
          }
  
  
          //// Called when the action mode is created; startActionMode() was called
          @Override
          public boolean onCreateActionMode(ActionMode mode, Menu menu)
          {
              // TODO Auto-generated method stub
              mode.getMenuInflater().inflate(R.menu.delete_only, menu);
              return true;
          }
  
           // Called when the user exits the action mode
          @Override
          public void onDestroyActionMode(ActionMode mode) 
          {
              // TODO Auto-generated method stub
              mActionMode = null;
          }
  
          //// Called each time the action mode is shown. Always called after onCreateActionMode, but
          // may be called multiple times if the mode is invalidated.
          @Override
          public boolean onPrepareActionMode(ActionMode mode, Menu menu)
          {
              // TODO Auto-generated method stub
              return false;
          }
  };
  </code></pre>
  
  <p>This is the on Item Click Listener for the list view</p>
  
  <pre><code>@Override
      public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long id) 
      {
          // TODO Auto-generated method stub
          if(listItemSelections.contains(1) &amp;&amp; mActionMode == null)
          {
              mActionMode = getActivity().startActionMode(mActionModeCallback);
          }
  
      }
  </code></pre>
  
  <p>This is the line that gives me the error </p>
  
  <pre><code>mActionMode = getActivity().startActionMode(mActionModeCallback);
  </code></pre>
  
  <p>It says </p>
  
  <pre><code>The method startActionMode(ActionMode.Callback) in the type Activity is not applicable for the arguments (ActionMode.Callback)
  </code></pre>
  
  <p>Im not sure what to do, I cant find a tutorial that explains the implementation within a fragment and using the support library. </p>
  
  <p>Thank you for reading. </p>