How to get the Scrollposition in the Recyclerview/Layoutmanager?

For future use, If you are switching between Fragments within the same activity and all you want to do is save scroll-position for recyclerview and then restore recyclerview to the same scroll-position, you can do as follows:

In your onStop()/onDestroyView()/onPause() whatever callback is more appropriate, do this:

Parcelable recylerViewState = recyclerView.getLayoutManager().onSaveInstanceState();

And In your onStart()/onCreateView()/onResume() whatever callback is more appropriate, do this:

recyclerView.getLayoutManager().onRestoreInstanceState(recylerViewState);

This way you can successfully keep your recyclerView's state in a parcelable and restore it whenever you want.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)