Skip to content Skip to sidebar Skip to footer

RecyclerView Scrolls To Top Position When Change The Adapter Data

I am doing the like and dislike for a post in a RecyclerView, I call the api after changing the view but the problem is that the RecyclerView always scrolls to the top when I notif

Solution 1:

Some tips:

  1. Don't use multiple objects of adapter. Use only single object and try to update the data. Don't set adapter again after updating data.

  2. After updating list just calling adapter.notifydatasetchanged() will solve your problem.

Hopefully this will solve your problem.


Solution 2:

Views need to have an id in order for them to save their state, so make sure all parent layouts of your RecyclerViews have an id.


Solution 3:

Not sure if this solves your problem but I was having the same issue and it was because I was calling setAdapter after notify. So, not calling setAdapter after notify solved the problem.

mAdapter.notifyItemRangeInserted(mAdapter.getItemCount(), list.size() - 1);

recyclerView.setAdapter(); // remove this line. //Do this only when you're setting the data for the first time or when adapter is null.


Post a Comment for "RecyclerView Scrolls To Top Position When Change The Adapter Data"