How to save and restore ListView position in Android

前端 未结 4 597
再見小時候
再見小時候 2021-02-03 15:05

I have tabView, displaying list in each tab. When I scroll in one tab, switch to another tab and return to previous tab, position is returned to the top instead of displaying pr

4条回答
  •  日久生厌
    2021-02-03 15:31

    Don't call setAdapter() again on the list view. Do something like this.

    if(myListView.getAdapter() == null)
        myListView.setAdapter(new myAdapter(this, R.layout.row, items));
    

    If you need to update your ListView call notifyDataSetChanged() on the adapter.

提交回复
热议问题