如何获得观OnContextItemSelected事件? [英] How to get View in OnContextItemSelected event?
问题描述
在公共无效onCreateContextMenu(文本菜单菜单视图V,ContextMenuInfo menuInfo}事件,
In public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo} event ,
我想我可以知道哪些控制使用下面的由ARG视图V推出onCreateContextMenu事件,对吧?结果
ImageView的ImageView的=(ImageView的)V
I think I can know which control launch onCreateContextMenu event by the arg View v using the following, right?
ImageView imageview=(ImageView)v
但在onContextItemSelected(菜单项项)公共布尔,我无法找到同样的阿根廷,我该怎么办?谢谢!
But In public boolean onContextItemSelected(MenuItem item), I can't find the same arg, how can I do? Thanks!
推荐答案
您可以使用ContextMenu.ContextMenuInfo。
You can use the ContextMenu.ContextMenuInfo.
类似的东西:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;
}
您还可以得到正在显示菜单中的确切查看:
You can also get the exact View for which the menu is being displayed:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;
View view = info.targetView;
}
看看这些问题:
这篇关于如何获得观OnContextItemSelected事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!