Maintain/Save/Restore scroll position when returning to a ListView

后端 未结 20 2058
無奈伤痛
無奈伤痛 2020-11-21 21:30

I have a long ListView that the user can scroll around before returning to the previous screen. When the user opens this ListView again, I want the

20条回答
  •  不要未来只要你来
    2020-11-21 22:06

    private Parcelable state;
    @Override
    public void onPause() {
        state = mAlbumListView.onSaveInstanceState();
        super.onPause();
    }
    
    @Override
    public void onResume() {
        super.onResume();
    
        if (getAdapter() != null) {
            mAlbumListView.setAdapter(getAdapter());
            if (state != null){
                mAlbumListView.requestFocus();
                mAlbumListView.onRestoreInstanceState(state);
            }
        }
    }
    

    That's enough

提交回复
热议问题