Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recyclerview on Scrolling values changing from adapter

I am working on an app where I am trying to populate a list using RecyclerView and recycler adapter as well. But when I scroll through the list quickly sometimes values on the list item shuffles among list items. Is there a known fix for this?

like image 847
Nilabja Avatar asked Feb 04 '16 12:02

Nilabja


People also ask

Does RecyclerView scroll?

To help you build apps with lists, Android provides the RecyclerView . RecyclerView is designed to be very efficient, even with large lists, by reusing, or recycling, the views that have scrolled off the screen.

What are differences between RecyclerView Adapter and ListAdapter?

ListAdapter is just an extension of RecyclerView. Adapter . Its computes diffs between Lists on a background thread with AsyncListDiff . You can obviously create a RecyclerView.

How do I stop refreshing RecyclerView data scroll to top position Android?

Just set your LayoutManager and adapter for the first time. Make a setDataList method in your adapter class. And set your updated list to adapter list. And then every time of calling API set that list to setDataList and call adapter.

What does notifyDataSetChanged do in RecyclerView?

notifyDataSetChanged. Notify any registered observers that the data set has changed. There are two different classes of data change events, item changes and structural changes. Item changes are when a single item has its data updated but no positional changes have occurred.


3 Answers

adding this in the adapter solved the problem

@Override
public int getItemViewType(int position)
{
    return position;
}
like image 72
Nilabja Avatar answered Oct 08 '22 12:10

Nilabja


Just Override these methods in your adapter class:

@Override
public long getItemId(int position) {
    return position;
}

@Override
public int getItemViewType(int position) {
    return position;
}

This link will help you to get the understanding of the concept behind.

How to fix Recyclerview shuffling issue

like image 21
Shujat Munawar Avatar answered Oct 08 '22 11:10

Shujat Munawar


Just have to override two methods in your Adapter and it will solve your issue.

@Override
public long getItemId(int position) {
    return position;
}

@Override
public int getItemViewType(int position) {
    return position;
}
like image 39
Vrajesh Avatar answered Oct 08 '22 10:10

Vrajesh