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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With