ContextMenu initiated from GridView

情到浓时终转凉″ 提交于 2020-01-11 10:28:04

问题


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


回答1:


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 :)



来源:https://stackoverflow.com/questions/38704558/contextmenu-initiated-from-gridview

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