问题
Strange, neither Fragment nor v4.Fragment implemented the "onContextMenuClosed". Other events are there, like onCreateContextMenu and onContextItemSelected.
I need to clean up something when the context menu is dismissed, which can be activated by back button, tapping on the blank area on screen, or select one menu item in the context menu.
How do I monitor the dismissal of a context menu in a fragment then?
回答1:
The menu close event in a fragment will also trigger its parent activity's "onContextMenuClosed". So I just override the event and pass it to a self implemented event handling function in the fragment.
// The parent activity.java:
@Override
public void onContextMenuClosed(Menu menu) {
super.onContextMenuClosed(menu);
childFragment.onContextMenuClosed(menu);
}
// The child fragment.java:
public void onContextMenuClosed(Menu menu) {
// Do you business here.
}
来源:https://stackoverflow.com/questions/16848058/oncontextmenuclosed-not-implemented-in-fragment