Note that there are some explanatory texts on larger screens.

plurals
  1. POInappropriate Context Menu within a Fragment
    text
    copied!<p>I have an activity with a Navigation Drawer and a fragment. Each of them has his own ListView with a Contextual Menu.</p> <p>The Context Menu inside the navigation drawer works fine.</p> <p>The problem is with the menu inside the fragment. When I enter the fragment's context menu, BOTH navigation drawer's menu AND fragment's menu are displayed.</p> <p><strong>Activity's methods</strong></p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { registerForContextMenu(mDrawerList); // mDrawrList is the navigation drawer's ListView } @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch(item.getItemId()) { case R.id.action_edit: // Do some stuff return true; case R.id.action_delete: // Do some stuff return true; } return super.onContextItemSelected(item); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.drawer, menu); } </code></pre> <p><strong>Fragment's methods</strong></p> <pre><code>@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); mListView = (ListView) view.findViewById(R.id.list); registerForContextMenu(mListView); // ... } @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch(item.getItemId()) { case R.id.action_edit: // Do some stuff return true; case R.id.action_delete: // Do some stuff return true; } return super.onContextItemSelected(item); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); getActivity().getMenuInflater().inflate(R.menu.fragment_menu, menu); } </code></pre> <p>Thank you in advance.</p>
 

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