Note that there are some explanatory texts on larger screens.

plurals
  1. POonContextItemSelected does not seem to be called
    primarykey
    data
    text
    <p>I am creating a very simple Activity based on a list view. I want to add a context menu to each one of the items in the list, so I called <code>registerForContextMenu(mListView)</code>. I then implemented the methods <code>onCreateContextMenu</code> and <code>onContextItemSelected</code>.</p> <p>The <code>onCreateContextMenu</code> works (the context menu appears correctly), but when I click on an item of this menu nothing happens, the context menu just disappears and the method <code>onContextItemSelected</code> is not called (I just put a log inside it to check).</p> <p>If it can help, note that the <code>ListView</code> also has a <code>onItemClickListener</code> attached to it.</p> <p>Did I forget something ?</p> <p>Thanks !</p> <p>EDIT: here's the code (I hid some irrelevant stuff)</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mListView = new ListView(this); mContacts = new Vector&lt;Contact&gt;(); mAdapter = new ContactAdapter(this, mContacts); registerForContextMenu(mListView); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new OnItemClickListener() { ... }; } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); if (v == mListView) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.list_item_contextmenu, menu); } } @Override public boolean onContextItemSelected(MenuItem item) { Log.v("Contacts", "onContextItemSelected called"); return super.onContextItemSelected(item); } </code></pre> <p>EDIT 2: I added the <code>onContextMenuClosed()</code> method, which is properly called when the menu is closed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload