How to save and restore the state of an ExpandableListView in Android?

后端 未结 4 939
醉酒成梦
醉酒成梦 2021-01-06 12:45

Is it possible to save and restore the state (which items are collapsed and which not) of an ExpandableListView in Android?

If it is possible, how can I do that?

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-06 13:01

    a simpler way could be, if you're using setOnGroupClickListner and setOnChildClickListener just keep the last selected ChildPosition and GroupPositin integer and later on check it and respond properly,

    if (childPosition > 0) {
        mExpandableList.expandGroup(groupPositin);
    }
    mExpandableList.setItemChecked(groupPositin + childPosition , true);
    

    you just need to remember set childPosition to 0 in your setOnGroupListener method.

提交回复
热议问题