在給ExpandableListView添加ContextMenu時,有時須要區分是group觸發的長按仍是child出發的長按,經過onCreateContextMenu的ContextMenuInfo參數能夠具體判斷出,具體代碼:java
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { ExpandableListContextMenuInfo adapterContextMenuInfo = (ExpandableListContextMenuInfo) menuInfo; View targetView = adapterContextMenuInfo.targetView; Object obj = targetView.getTag(); // group的長按事件時 if (obj != null && Constants.GROUP_VIEW.equals(obj.toString())) { menu.add(0, 0, 0, "delete"); } }