我有兩個ContextMenu
的在同一Activity
或Fragment
。兩個ContextMenu在同一活動/片段
這裏是onCreateContextMenu
,我處理他們兩個:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Available Actions");
if (v == listView) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
position = info.position;
menu.add(2, 1, 1, "Edit");
menu.add(2, 2, 2, "Delete");
menu.add(2, 3, 3, "Share");
}
if (v == iPP) {
menu.add(1, 4, 1, "Pick From Gallery");
menu.add(1, 5, 2, "Capture Picture");
menu.add(1, 6, 3, "Remove");
}
super.onCreateContextMenu(menu, v, menuInfo);
}
當我舔了listView
之一,它膨脹「編輯,刪除,共享」就好了。但是當我點擊iPP時,它會爲iPP
和listView
充氣6個選項?
任何人都可以看到發生了什麼?
注:iPP
是ImageView
'ContextMenu.add(...)'只是將項目添加到任何已存在的項目。在每個'if'條件塊中,在添加項目之前調用'menu.clear()'。 – Squonk
我建議你使用'ContextualActionBar' insted,它似乎更適合你的情況。 – Leandros
@Squonk那麼問題是,只要'iPP'是視圖,它由於某種原因調用錯誤的三秒鐘(從'listView')。所以'menu.clear(),'清除不正確的三個。不知道爲什麼onCreateContext似乎第二次觸發。 – KickingLettuce