ExpandableListView扩展&坍方

时间:2014-09-11 11:15:10

标签: android expandablelistview

您好我是Android应用新手现在我很震惊地维护ExpandableListView ..群组没有崩溃,请让我知道如何解决此问题,在此先感谢

以下是我正在处理的代码,如果代码中有任何错误请告诉我

@Override
public void onGroupCollapsed(int groupPosition) {
 super.onGroupCollapsed(groupPosition);
}

@Override
public void onGroupExpanded(int groupPosition) {

    //if(IsExpanded)
    //{
        if(lastExpandedGroupPosition != -1 && groupPosition != lastExpandedGroupPosition){
             onGroupCollapsed(lastExpandedGroupPosition);
             }
        else { super.onGroupExpanded(groupPosition); }
    //}

    lastExpandedGroupPosition = groupPosition;

}

1 个答案:

答案 0 :(得分:3)

if语句中的

而不是

onGroupCollapsed(lastExpandedGroupPosition);

listView.collapseGroup(lastExpandedGroupPosition);

或者我认为除了Expanded之外你想要崩溃所有你可以使用这样的东西

public void onGroupExpand(int groupPosition) {
    int lenght = adapter.getGroupCount();
    for (int i = 0; i < lenght; i++) {
        if (i != groupPosition) {
            listView.collapseGroup(i);
        }
    }
}