以编程方式在ExpandableListView中扩展特定组

时间:2019-07-11 08:31:35

标签: android android-listview

[我的问题不是重复的,因为我没有使用过ImageView] 我尝试使用下面的方法,但它扩展了所有组

 //method to expand all groups
    private void expandAll() {
        int count = expandableCategoryAdapter.getGroupCount().;
        for (int i = 0; i < count; i++) {
            expandableListView.expandGroup(i);
        }
    }

1 个答案:

答案 0 :(得分:0)

在这里,您正在显式扩展 ExpandableListView 中的所有组,这就是为什么所有组都得到扩展的原因。

请勿使用:

 //method to expand all groups
private void expandAll() {
    int count = expandableCategoryAdapter.getGroupCount();
    for (int i = 0; i < count; i++) {
        expandableListView.expandGroup(i);
    }
}

使用此:

expandableListView.setOnGroupClickListener((parent, v, groupPosition, id) -> {
                    expandableListView.expandGroup(groupPosition);
                    return false;
});
相关问题