2
任何人都可以親切地指導我如何調用菜單項按下上下文菜單。我用google搜索了很多,但沒有發現。 期待您的寶貴幫助。 Regards, Rony在菜單項上調用android上下文菜單按
任何人都可以親切地指導我如何調用菜單項按下上下文菜單。我用google搜索了很多,但沒有發現。 期待您的寶貴幫助。 Regards, Rony在菜單項上調用android上下文菜單按
您可能正在尋找openContextMenu(view)
。在菜單的onclick中調用它()
要創建上下文菜單,請覆蓋onCreateContextMenu
和onContextItemSelected
。請參閱谷歌的例子。
您只需要實現此功能。它會工作。
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
Log.e(LOGTAG, "Tao menu");
if(v == expList)
{
super.onCreateContextMenu(menu, v, menuInfo);
//AdapterContextMenuInfo aInfo = (AdapterContextMenuInfo) menuInfo;
// We know that each row in the adapter is a Map
//HashMap map = (HashMap) simpleAdpt.getItem(aInfo.position);
menu.setHeaderTitle("Options");
menu.add(1, 1, 1, "Reprint");
menu.add(1, 2, 1, "Void");
menu.getItem(0).setOnMenuItemClickListener(new OnMenuItemClickListener()
{
public boolean onMenuItemClick(MenuItem clickedItem)
{
return true;
}
});
menu.getItem(1).setOnMenuItemClickListener(new OnMenuItemClickListener()
{
public boolean onMenuItemClick(MenuItem clickedItem)
{
return true;
}
});
}
}
你好,請讓我知道,我應該給到位的觀點....片斷附在這裏 - http://pastebin.com/uh9LXCY2 – user264953 2010-11-09 12:55:06
嗯,這實際上取決於,是它是該活動中唯一的上下文菜單?如果是,則使用'getCurrentFocus()' – st0le 2010-11-09 12:59:32
號我有一個listview。我調試和檢查.. getCurrentFocus()返回列表視圖 – user264953 2010-11-09 13:13:45