The long id parameter passed by the onItemLongLongClick method is a packed value. You can get the group position using ExpandableListView.getPackedPositionGroup(id) Child position is obtained using ExpandableListView.getPackedPositionChild(id) . If Child == -1, then a long click was in the group element.
The following is an example listener class demonstrating id unpacking.
private class expandableListLongClickListener implements AdapterView.OnItemLongClickListener { public boolean onItemLongClick (AdapterView<?> p, View v, int pos, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setTitle("Long Click Info"); String msg = "pos="+pos+" id="+id; msg += "\ngroup=" + ExpandableListView.getPackedPositionGroup(id); msg += "\nchild=" + ExpandableListView.getPackedPositionChild(id); builder.setMessage(msg); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } } ); AlertDialog alert = builder.create(); alert.show(); return true; } }
ebachalo Feb 21 2018-12-12T00: 00Z
source share