简体   繁体   中英

RecyclerView shuffles items and changing values on scrolling fast in adapter, Android Studio

I am using RecyclerView to place JSON data, and in adapter, I set some conditions that specific values have different values then hide the RelativeLayout.

On the app run, everything works fine But when I scroll the data, the hidden or invisible field gets visible.

Now I want the solution to this problem, that when I scroll the RecyclerView, the data should be in its defined state instead of shuffling or changing its state because of its position.

The solution is very simple, here just have to override two methods in Adapter class and it will solve the issue.

The reason is because some other overridden methods need to call these override methods while rendering the list items.

Place this code in the end of adapter class. As Example: https://i.stack.imgur.com/Q81Ud.png

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM