对于那些遇到与我相同的问题的人,我将把它留在这里:
我试图为一个设置OnItemLongClickListener一个ExpandableListView并想知道点击了哪个组。遵循我正在使用的关于 SO(例如这个问题ExpandableListView.getPackedPositionGroup)的许多问题的建议,但它总是返回0。
这是我使用的代码:
@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;
}
我发现 position 和 id 总是具有相同(正确)的值。但是,类型始终被识别为组,并且解包位置始终为 0。
那么这段代码有什么问题呢?