私はを使用していExpandableListView lvます。これは私が持っているものです。
ExpandableListView lv=(ExpandableListView )findViewById(....);
lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener(){
@Override
public boolean onChildClick(ExpandableListView parent, View v,int gp, int cp, long id) {
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;
}
});
子アイテムを長押しするcustomMenu.show(v)とが呼び出され、指を離すとOnClickListenerが呼び出されます。同様に、グループアイテムを長押ししてから指を離すと、そのアイテムContextmenuListenerが呼び出され、グループが展開されて子アイテムが表示されます。これは正常な動作ですか?これを防ぐにはどうすればよいですか?
私は実際にlong Clickリストアイテムに何かをしたいです。trueオンに戻るとlongClickListener正しく機能します(クリックイベントが発生します)。ただし、アイテムのID、グループ、および子の位置も取得する必要があります。これはContextMenuInfo、contextmenuリスナーでのみ提供されます。