私はを使用してい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
リスナーでのみ提供されます。