为什么registerForContextMenu传递onCreateContextMenu空ContextMenuInfo? [英] Why is registerForContextMenu passing onCreateContextMenu a null ContextMenuInfo?

查看:165
本文介绍了为什么registerForContextMenu传递onCreateContextMenu空ContextMenuInfo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的onCreate,我附上一个线性布局视图给一个变量活动视图。然后,我打电话 registerForContextMenu(活动视图)。看来,一切工作正常,上下文菜单被创建,该项目是可以点击的,但是,在 onContextItemSelected ,我称之为 AdapterContextMenuInfo信息=(AdapterContextMenuInfo) item.getMenuInfo(),我得到一个NullPointerException异常。我跟踪的空menuInfo变量的所有回来的路上找到 registerForContextMeu(活动视图)从一开始就通过OnCreateContextMenu空ContextMenuInfo。这究竟是为什么?我做同样的过程,不同的看法,一个ListView,旁边的的LinearLayout,这个问题不存在那里。

In onCreate, I attach a linear layout view to a variable activeView. I then call registerForContextMenu(activeView). It appears that everything works properly, the context menu gets created, the items are clickable, however, in onContextItemSelected, I call AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo() and I get a nullpointerexception. I've traced the null menuInfo variable all the way back to find that registerForContextMeu(activeView) is passing OnCreateContextMenu a null ContextMenuInfo from the start. Why is this happening? I do the same process for a different view, a listView, alongside the linearlayout, and the problem doesn't exist there.

推荐答案

什么是你希望摆脱getMenuInfo的()?在任何情况下,我不认为它会通过的LinearLayout填充去做,相信顶多你就可以得到这催生菜单中的视图(相同的LinearLayout)。

What are you expecting to get out of getMenuInfo()? In any case, I don't think it will be populated by a LinearLayout, I believe at most you'll be able to get the View (the same LinearLayout) which spawned the menu.

这篇关于为什么registerForContextMenu传递onCreateContextMenu空ContextMenuInfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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