How Do I Store Users Position From Recyclerview And Use Scrolltoposition() To Cast It?
I am using a RecyclerView to display movie posters in a Gridlayout. My goal is to save the position of the user, so when they rotate the phone it will save their position. movieGri
Solution 1:
Try saving just the position and restore with that instead.
private static final String SCROLL_POSITION = "SCROLL_POSITION";
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(SCROLL_POSITION, ((LinearLayoutManager) movieGrid.getLayoutManager()).findFirstVisibleItemPosition());
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
final int position = savedInstanceState.getInt(SCROLL_POSITION);
movieGrid.postDelayed(new Runnable() {
public void run() {
movieGrid.scrollToPosition(position);
}
}, 300);
}
Post a Comment for "How Do I Store Users Position From Recyclerview And Use Scrolltoposition() To Cast It?"