I created an ExpandableListView with the help of this tutorial: link. I understand the code more or less and been trying to set a longclicklistener on the groups.
There
Group items are a subset of all items, so the method above should be called in either case. You'd then use getPackedPositionType as above to figure out if the selected item is a group, an item, or null.
The code for this would be:
exList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
int itemType = ExpandableListView.getPackedPositionType(id);
if ( itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
childPosition = ExpandableListView.getPackedPositionChild(id);
groupPosition = ExpandableListView.getPackedPositionGroup(id);
//do your per-item callback here
return retVal; //true if we consumed the click, false if not
} else if(itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
groupPosition = ExpandableListView.getPackedPositionGroup(id);
//do your per-group callback here
return retVal; //true if we consumed the click, false if not
} else {
// null item; we don't consume the click
return false;
}
});
If it's a group, you'll use getPackedPositionGroup as above to get the group ID that is being long-pressed. If it's an item, you'll use the combination of getPackedPositionGroup and getPackedPositionChild.