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

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

    Improving Floaf's answer: declare

     public static int firstVisiblePosition=0;
    

    on Pause

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

    onResume

    for (int i=0;i

    This will not only restore each group's state but it will also scroll to the childView that was viewed when activity paused.

提交回复
热议问题