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

后端 未结 4 959
醉酒成梦
醉酒成梦 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:05

    I iterate through the groups and save the state of them all:

    int numberOfGroups = MyExpandableListViewAdapter.getGroupCount();
    boolean[] groupExpandedArray = new boolean[numberOfGroups];
      for (int i=0;i

    Then for restore the state:

    for (int i=0;i

    I don't understand what you mean by how to access the ListView in onPause() / onResume(), it should be accessible from there if you store the ListView object as a member of the activity class.

提交回复
热议问题