Skip to content Skip to sidebar Skip to footer

Recyclerview Pagination Using Asynctask Making Duplicate Pages?

I have a gallery application that is parsing the Reddit API and populating a recyclerview list with images. Each page contains 25 pictures from that subreddit. But this code is mak

Solution 1:

You are getting overlapping calls to FetchItemsTask due to how onScrollStateChanged works. If you swipe up and let things settle, here is how onScrollStateChanged is invoked:

onScrollStateChanged: SCROLL_STATE_DRAGGING onScrollStateChanged: SCROLL_STATE_SETTLING onScrollStateChanged: SCROLL_STATE_IDLE

This is what you would expect. If, however, you swipe up and then swipe up again before the view settles, this is what happens:

onScrollStateChanged: SCROLL_STATE_DRAGGING onScrollStateChanged: SCROLL_STATE_SETTLING onScrollStateChanged: SCROLL_STATE_DRAGGING onScrollStateChanged: SCROLL_STATE_SETTLING onScrollStateChanged: SCROLL_STATE_IDLE

This may seem surprising at first, but it makes sense if you think about it.

You are also not doing any checks for the newState in onScrollStateChanged.

If you are trying to implement an endless RecyclerView try searching for "endless recyclerview". There are many good resources on the web.

Post a Comment for "Recyclerview Pagination Using Asynctask Making Duplicate Pages?"