简体   繁体   English

android从listview问题中加载更多项目

[英]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. listview的项目是一些帖子,存储在服务器上。 (Currently using Parse, but this doesn't matter) (当前正在使用Parse,但这无关紧要)

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. 每次我将项目加载到列表视图时,我都会向服务器发出请求,并假设有15条帖子(按降序排列)。 So the first request will give me the last 15 posts added. 因此,第一个请求将给我添加的最后15个帖子。 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. 当我单击“添加更多”时,它将跳过15个请求,以添加下15个帖子。如果再次单击,它将跳过30个帖子,请求接下来的15个帖子,依此类推。

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 . 如果您可以编辑Web服务的代码,那么可以在Twitter开发者文档/使用时间轴中找到处理分页的良好指南。 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. 如果不能,那么我唯一想到的就是在添加适配器数据之前,检查帖子id (如果有id ,或者为每个id创建一个本地标识符)。 If it's already there then you skip it and just move to the next one. 如果已经存在,则可以跳过它,然后移至下一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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