ListViews and GridViews are great widgets to use in an Activity for your app. Sometimes it is useful to also create smaller versions of them for dialogs within your app. There’s only one problem: Context Menus. If you have tried to put a context menu on a ListView inside a dialog, you may have found out that while onCreateContextMenu() is called, onContextItemSelected() is not. There is a workaround, though, because onContextItemSelected() is actually a convenience method called from onMenuItemSelected(int, MenuItem). If you add the following method to your dialog containing the ListView (or GridView), you will find that onContextItemSelected() is working again.
@Override public boolean onMenuItemSelected(int aFeatureId, MenuItem aMenuItem) { if (aFeatureId==Window.FEATURE_CONTEXT_MENU) return onContextItemSelected(aMenuItem); else return super.onMenuItemSelected(aFeatureId, aMenuItem); }
Hi
Do you know what is needed to make onContextMenuClosed() be called?
Im using the context menu (android 4.0) inside a Dialog class. In my case the trick with onMenuItemSelected was not need. I tried onOptionsMenuClosed but it is not called neither.
Please reply to my email in case of some clues 🙂
No email address was provided by your comment, so cannot reply via that method.
I do not know offhand why that would not be called, but if I had to guess, I would say to look at onPanelClosed.