title: How to get Action Mode working with a ListView
body: <p>I'm trying to get a contextual menu using the Action Mode where I can select an item in a ListView by long-clicking on it. I created a MultiChoiceListener according to <a href="http://developer.android.com/guide/topics/ui/menus.html#context-menu" rel="nofollow noreferrer">this reference</a> and made a ItemLongClickListener wich sets an item as checked which is needed for the Action Mode to work according to <a href="https://stackoverflow.com/questions/9283181/how-do-i-use-a-selectable-list-with-a-contextual-actionbar">this reference</a>.</p>
  
  <p>My problem is, that, even if the item long clicked animation is playing, the ActionMenu doesn't inflate.</p>
  
  <p>ListView Code:</p>
  
  <pre><code>final ListView listView = (ListView) findViewById(android.R.id.list);
          listView.setAdapter(adapter);
          listView.setLongClickable(true);
          listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
          listView.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long id) {
  
              Cursor cursor = db.getSubject(id);
              String subject = null;
              try {
                  subject = cursor.getString(cursor.getColumnIndex("subject"));
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              Intent intent = new Intent(Main.this, Marks.class);
              intent.putExtra("selected", subject);
              startActivity(intent);
              }
          });
          listView.setOnItemLongClickListener(new OnItemLongClickListener() {
  
              @Override
              public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1,
                      int arg2, long arg3) {
                  listView.setItemChecked(arg2, true);
                  return true;
              }
  
          });
  
          listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
  
              @Override
              public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                  // TODO Auto-generated method stub
                  return false;
              }
  
              @Override
              public void onDestroyActionMode(ActionMode mode) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                  MenuInflater inflater = mode.getMenuInflater();
                  inflater.inflate(R.menu.context, menu);
                  return true;
              }
  
              @Override
              public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                  // TODO Auto-generated method stub
                  return false;
              }
  
              @Override
              public void onItemCheckedStateChanged(ActionMode mode, int position,
                      long id, boolean checked) {
                  // TODO Auto-generated method stub
  
              }
          });
  </code></pre>
  
  <p>Thanks in advance!</p>