Prevent Scroll Position RecyclerView (PSPR)

Hi guys, recently I was faced with the case of creating a nested recyclerview display, and each item is editable, then when I update the related item and then refresh the recyclerview, I started to get overwhelmed when I didn't know how to maintain the scroll focus position, because by default when the recyclerview is refreshed, the scroll position returns to the top.

Okay, after surfing for quite a while, I finally found what I was looking for. Here are some easy steps to maintain the current position of the recyclerview when it is refreshed.

// Save state
private Parcelable recyclerViewState;
recyclerViewState = recyclerView.getLayoutManager().onSaveInstanceState();

// Restore state
recyclerView.getLayoutManager().onRestoreInstanceState(recyclerViewState);

Done!


Post a Comment

Previous Next

نموذج الاتصال