片段中未实现onContextMenuClosed [英] onContextMenuClosed not implemented in Fragment

查看:128
本文介绍了片段中未实现onContextMenuClosed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪,Fragment和v4.Fragment都未实现"onContextMenuClosed".还有其他事件,例如onCreateContextMenu和onContextItemSelected.

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?

推荐答案

片段中的菜单关闭事件也将触发其父活动的"onContextMenuClosed".因此,我只是重写事件,并将其传递给片段中的一个自我实现的事件处理函数.

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.
}

这篇关于片段中未实现onContextMenuClosed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆