For those encountering the same problem as me I'll leave this here:
I was trying to set up a OnItemLongClickListener
for an ExpandableListView
and wanted to know which group was clicked. Following the advice of many questions here on SO (for example this question) I was using ExpandableListView.getPackedPositionGroup
, however it always returned 0
.
Here's the code I used:
@Override
public boolean onItemLongClick(AdapterView<?> list, View view, int position, long id) {
Log.d(D, "position: "+position);
Log.d(D, "id: "+position);
Log.d(D, "unpacked position: "+ExpandableListView.getPackedPositionGroup(position));
switch(ExpandableListView.getPackedPositionType(position)) {
case ExpandableListView.PACKED_POSITION_TYPE_CHILD:
Log.d(D, "position type: child");
break;
case ExpandableListView.PACKED_POSITION_TYPE_GROUP:
Log.d(D, "position type: group");
break;
case ExpandableListView.PACKED_POSITION_TYPE_NULL:
Log.d(D, "position type: null");
break;
default:
Log.wtf(D, "position type: "+ExpandableListView.getPackedPositionType(position));
}
return true;
}
What I found is that position and id always had the same (correct) value. However, the type was always recognised as group and the unpacked position was always 0.
So what is wrong with that code?