简体   繁体   中英

android load more items from listview issue

I have a listview, i've edited the adapter, so the last item will always be a button with the text 'Load More'. The items of the listview are some posts, that are stored on a server. (Currently using Parse, but this doesn't matter)

Everytime I load items to the listview, I do a request to the server, and get let's say 15 posts, sorted by the date descending. So the first request will give me the last 15 posts added. When I click add more, it will do a request for the next 15 posts added, by skipping 15. If I click again , it will do a request for the next 15 posts by skipping 30 posts, and so on.

This method works perfectly if no one ads a new post while scrolling. But if this happens, I would get some of the posts that I already have..

What should I do to handle new posts using this method? Or is there a better one?

If you can edit your web service's code then a good guideline to handle paginating can be found in the Twitter devs documentation/Working with Timelines . It is a good place to start.

If you can't then the only thing that I can think of is checking the posts id (if it has one, or create a local identifier for each one of them) before adding the post you your adapter's data. If it's already there then you skip it and just move to the next one.

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