2019独角兽企业重金招聘Python工程师标准>>>
在给ExpandableListView添加ContextMenu时,有时需要区分是group触发的长按还是child出发的长按,通过onCreateContextMenu的ContextMenuInfo参数可以具体判断出,具体代码:
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");}}