2013-07-17 57 views
8

在公共無效onCreateContextMenu(文本菜單菜單,視圖V,ContextMenuInfo menuInfo}事件,如何在OnContextItemSelected事件中獲取視圖?

我想我可以知道哪個控制使用以下,對不對?
的ImageView的ImageView =由ARG視圖V推出onCreateContextMenu事件(ImageView的)v

但在公共布爾onContextItemSelected(菜單項的項目),我無法找到同樣的阿根廷,我該怎麼辦謝謝

+0

可能重複:如何找到從上下文菜單中點擊的位置(http://stackoverflow.com/questions/2453620/android-how-to-find-the-position-clicked-from-the-context-menu) – hasanghaforian

回答

16

可以使用ContextMenu.ContextMenuInfo這樣的:?!

@Override 
public boolean onContextItemSelected(MenuItem item) { 
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); 
    int index = info.position; 
} 

您也可以將正在顯示菜單中的確切查看:

@Override 
public boolean onContextItemSelected(MenuItem item) { 
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); 
    int index = info.position; 
    View view = info.targetView; 
} 

看看這些問題:的[安卓

Android: How to find the position clicked from the context menu

Identifying the view selected in a ContextMenu (Android)

相關問題