How to save and restore ListView position in Android

前端 未结 4 598
再見小時候
再見小時候 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条回答
  •  梦毁少年i
    2021-02-03 15:28

    To get the current position of your ListView, you can call

    int position = mCatchList.getFirstVisiblePosition();
    

    Then once you navigate back to the tab with that ListView, you can call

    mCatchList.setSelection(position);
    

    It will depend on how your code is written to tell if the position will need to be added to the savedInstanceState, or however.

提交回复
热议问题