我正在使用ExpandableListView
lv
。這就是我所擁有的。 ExpandableListView lv =(ExpandableListView)findViewById(....); lv.setOnChildClickListener(新ExpandableListView.OnChildClickListener(){ @覆蓋 公共布爾onChildClick(ExpandableListView父母,視圖V,INT GP,INT CP,長ID){即使長時間點擊,Onclick事件也會執行
Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_SHORT).show();
//perform action
return true;
}
});
lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu contextMenu, View v,ContextMenuInfo menuInfo) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
customMenu.show(v);
//do other stuff
contextMenu=null;
}
});
當我長點擊一個clild項目,調用customMenu.show(v)
,當我鬆開手指時,調用其OnClickListener
類似地,在長按然後鬆開組項目上的手指時,會調用其ContextmenuListener,然後該組展開以顯示子項目。這是正常行爲嗎?我如何防止這種情況?
我實際上想在long Click
的列表項上做東西。 longClickListener
返回true
正常工作(消耗點擊事件)。 但我還需要獲取項目的ID,組和子位置,這是通過ContextMenuInfo在上下文菜單監聽器中提供的。
不應該調用lv.registerForContextMenu()來代替嗎? – 2013-02-27 13:25:59
好吧,當我試圖通過添加一些菜單項來顯示contextmenu時,它正常運行。但我不想這樣做。我想顯示自己的菜單,而不是像給定的代碼。 – arnab321 2013-02-27 16:57:09
編輯問題 – arnab321 2013-02-27 17:29:20