我正在使用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