从GridView启动的ContextMenu [英] ContextMenu initiated from GridView

查看:166
本文介绍了从GridView启动的ContextMenu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我将GridView对象注册为一个上下文菜单,如下所示:

  registerForContextMenu(gridview); 

如何确定网格菜单是从哪个视图对象/平方开始的?



任何帮助将非常感谢

解决方案

onContextItemSelected()方法,您可以使用以下方法获取网格上的项目索引:

  AdapterView.AdapterContextMenuInfo info =(AdapterView.AdapterContextMenuInfo)item.getMenuInfo(); 
int index = info.position;

然后使用这个索引

Just wondering if anyone can help with this - I'm learning and unable to figure it out......

If I register a GridView object with a Context Menu as follows:

registerForContextMenu(gridview);

How can I determine which View object/square in the Grid the menu was initiated from?

Any help would be very much appreciated

解决方案

In onContextItemSelected() method, you can get the index of the item on the Grid by using:

AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;

Then use this index for everything you want :)

这篇关于从GridView启动的ContextMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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