ExpandableListView 点击处理

ExpandableListView click handling

两个问题:

  1. 我只想允许用户长按子项目,前提是它们位于我的可扩展列表视图的第一组中。在任何其他组下,都不应该允许这样做。我该怎么做?

  2. 我希望允许用户长按除第一个之外的所有组项目。

我将在 ExpandableListViews onItemLongClickListener 中处理这两个问题。

目前我有:

    @Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    if (bunchesExpListView.getPackedPositionType(id)==ExpandableListView.PACKED_POSITION_TYPE_GROUP) { // long click on bunch
        BunchLongClickDialog bunchLongClickDialog = new BunchLongClickDialog();
        Bundle bundle = new Bundle();
        bundle.putInt("group_position", position);
        bunchLongClickDialog.setArguments(bundle);
        bunchLongClickDialog.show(getFragmentManager(), "bunch_long_click_dialog");
    }
    return true;
}

这只会告诉我是否正在单击一个组,它不会检查该组是否是第一个组,也不会解决第一个问题。

autobot_101 用他的 post here 帮助我回答了我的问题。

基本上,您可以在执行任何条件之前使用 getPackedPosition 来获取 groupPosition 和 childPosition!