onContextMenuClosed not implemented in Fragment

别说谁变了你拦得住时间么 提交于 2021-02-10 09:46:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!