I have button, which displays a Context menu. In the menu are few items (some of them are disabled - setEnabled(false)).
Which event is called when a user click on the disabled item开发者_如何学Go? It's not onContextItemSelected nor onContextMenuClosed. But the menu is closed after the click.
Thanks for your help.
After consultation with my teacher, I've solved the problem. You can check the focus of your window, and then decide if the context menu was closed or not.
So you have to:
- Use the code below.
- Call onPrepareContextMenu() method when you create the context menu.
The code:
public class MyActivity extends android.app.Activity {
private boolean contextMenuDisplayed = false;
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus && this.contextMenuDisplayed) {
this.contextMenuDisplayed = false;
this.onContextMenuClosed(null);
}
}
public void onPrepareContextMenu() {
this.contextMenuDisplayed = true;
}
}
精彩评论