如何找出上下文菜单中单击了哪个网格行?
我有一个类似于网格的自定义布局。我将其注册为上下文菜单。现在,如果我长按它,我想知道用户单击的位置。我必须让我的自定义布局实现 MenuInfo 对吗?但是点击位置呢?
I've got a custom layout which is like a grid. I registered it for contextmenu. Now if I do a long click on it, I'd like to know the position where the user clicked on. I have to let my custom layout implement MenuInfo right? But what about the click position?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
onContextItemSelected()
中,如果上下文菜单适用于AdapterView
(例如GridView
),您可以强制转换item.getMenuInfo ()
对象到 AdapterView.AdapterContextMenuInfo 对象。该对象有一个id
和一个position
字段。如果您使用的是CursorAdapter
,则id
是_ID
。position
是适配器的索引。In
onContextItemSelected()
, if the context menu is for anAdapterView
(e.g.,GridView
), you can cast theitem.getMenuInfo()
object to anAdapterView.AdapterContextMenuInfo
object. That object has anid
and aposition
field. Theid
is the_ID
if you are using aCursorAdapter
. Theposition
is the index into your adapter.