Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying the group that has been clicked in an expandableListView

I'm trying to identify a view that has been clicked in an expandableListView. When I set an OnItemLongClickListener I get an argument that shows me the position of the clicked view inside the list. However, it also counts child views. I'd like it to count only groups, so when a group was clicked I can determine which one it was. Is there a way to do that?

like image 635
Lars Avatar asked Feb 25 '23 09:02

Lars


1 Answers

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.

like image 85
Nikolai Grigoriev Avatar answered Apr 30 '23 18:04

Nikolai Grigoriev