Identifying The Group That Has Been Clicked In An Expandablelistview
Solution 1:
No, the long parameter is not the packed value, this is the ID generated by your adapter (getCombinedChildId()
). Attempting to interpret an ID, even if you generate it in a certain way would be a bad idea. Id is an id.
I believe the right way is to use ExpandableListView.getExpandableListPosition(flatPos)
method. Your "pos" argument passed to the listener is, in fact, flat list position. getExpandableListPosition()
method returns the packed position which can be then decoded into separate group and child positions using the static methods of ExpandableListView
.
I have hit this problem myself today so I am describing the solution I have found working for me.
Solution 2:
The long id
parameter passed by the onItemLongLongClick
method is a packed value.
You can retrieve group position with ExpandableListView.getPackedPositionGroup(id)
Child position is obtained with ExpandableListView.getPackedPositionChild(id)
.
If Child == -1 then the long click was on the group item.
- Android: Access Textview Inside Child Of Expandablelistviewactivity
- Android :- Custom Expandablelistview : Cannot Expand Group Item To Display Child Item In Customlistview
- How To Draw Brushes Or Shape Using Path When Moving Finger Fast In Andorid Canvas (generate Missing Point When User Move Finger Fast)
Below is an example listener class demonstrating unpacking of id
.
privateclassexpandableListLongClickListenerimplementsAdapterView.OnItemLongClickListener {
publicbooleanonItemLongClick(AdapterView<?> p, View v, int pos, long id) {
AlertDialog.Builderbuilder=newAlertDialog.Builder(ctx);
builder.setTitle("Long Click Info");
Stringmsg="pos="+pos+" id="+id;
msg += "\ngroup=" + ExpandableListView.getPackedPositionGroup(id);
msg += "\nchild=" + ExpandableListView.getPackedPositionChild(id);
builder.setMessage(msg);
builder.setPositiveButton("Ok", newDialogInterface.OnClickListener() {
publicvoidonClick(DialogInterface dialog, int id) { }
} );
AlertDialogalert= builder.create();
alert.show();
returntrue;
}
}
Post a Comment for "Identifying The Group That Has Been Clicked In An Expandablelistview"