Reputation: 1
I have RecycleView inside the ScrollView that can infinite scroll and always load new data with paging. Is there any way to save my scroll position (RecycleView and ScrollView) when Activity get onPause(), and restore when onResume().
Just like Instagram, Facebook, etc. when we click for detail posting and back to the timeline exactly in the same position when we left beforeenter code here
.
Upvotes: 0
Views: 356
Reputation: 265
My advice : use RecycleView inside another RecycleView. So for RecycleView you can use this strategy : 1) Save last visible item position 2) Do some manipulations 3) Restore your position
int lastViewedPosition = ((LinearLayoutManager)rv.getLayoutManager()).findLastVisibleItemPosition();
//some manipulations
rv.getLayoutManager().scrollToPosition(lastViewedPosition + data.size() - 1);
Upvotes: 1