1

I have a RecyclerView that displays a list of images and text that are downloaded from the internet via a RecyclerView adapter. The problem arises when I scroll up and down the RecyclerView. As I scroll down the list initially, everything seems fine and all the CardViews (a cardview containing an image and some text) are in their respective positions.

However, as I begin to scroll back up, all the previous CardViews are replaced by the lowest CardView. The lowest item of the recyclerview is reused to replace all the previous items in the RecyclerView.

Is this a RecyclerView bug? If not is there some way to solve this issue by maybe clearing the RecyclerView's cache or by forcing RecyclerView to recycle the correct items?

Advait Saravade
  • 3,029
  • 29
  • 34

1 Answers1

1

It was actually a problem in my adapter implementation. I had a Cursor in the overriden onBindViewHolder method and every time it called cursor.moveToNext() the cursor would move forward unless it was the last row in the database. At that point it would stop on that last row. So when I scrolled up the screen, the recyclerview worked perfectly, except now it showed me the same data from the last row that the cursor had given it. I thought this might have been a recyclerview bug initially, but as it turns out, this was a bug in my code. To solve it I simply changed cursor.moveToNext() to cursor.moveToPosition(position) and it started displaying results as expected.

Advait Saravade
  • 3,029
  • 29
  • 34