How to update expandable list view when adapter's data changes

后端 未结 2 1188
挽巷
挽巷 2020-12-16 23:50

I have an activity that extends ExpandableListActivity. I use SimpleCursorTreeAdapter to fill ExpandableListView. My layout contains list view and empty view. On app start E

相关标签:
2条回答
  • 2020-12-17 00:16

    So, the answer is:

    1. Call cursor.requery() before calling adapter's notifyDataSetChanged() method.
    2. Save groups state in activity's onPause() method and restore in onResume() method.
    0 讨论(0)
  • 2020-12-17 00:37

    Re: Question # 2...

    Why can't you simply call View.invalidateViews() and View.requestLayout() in that order?

    If you already have your adapter set to the view, then you shouldn't need to requery, do you? By invalidating the view, and requesting the layout, you won't lose any of the states of your view.

    For example, in your "onResume" method, invalidate your list view by calling something like "lv.invalidateViews()". Next, call "lv.requestLayout()".

    Your "onCreate" method should still be responsible for setting up the adapters and linking an adapter to the view. To link the adapter, consider using "lv.setListAdapter()" instead of the former so that you aren't messing with the other views on the screen.

    0 讨论(0)
提交回复
热议问题