Refreshing Data in Recyclerview and Keeping Its Scroll Position

Refreshing data in RecyclerView and keeping its scroll position take user to the top of the activity

On item click, use call RecyclerView's smoothScrollToPosition(0) method.

You can see an example in this answer.

Update RecyclerView while keeping its scroll position

You can get the current position, refresh the adapter and smooth scroll to the previous position like this:

RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(context) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};

Then set the position to scroll to:

smoothScroller.setTargetPosition(position);
layoutManager.startSmoothScroll(smoothScroller);


Related Topics



Leave a reply



Submit