Android中的Firebase分页 [英] Firebase pagination in Android

查看:31
本文介绍了Android中的Firebase分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个图像发布应用程序,我想在其中获取前五个记录,然后当用户向下滚动到底部时,应该自动获取下五个记录.我正在按"negative_time stamp"订购,以便最新帖子位于顶部.从底部获取前5条记录后,我需要接下来的5条记录.请帮忙 .在此先感谢;

I am making a image posting app in which I want to fetch first five records and then when the user scrolls down to bottom next 5 records should be fetched automatically . I am ordering by "negative_time stamp" so that the latest post comes at the top . After fetching first 5 records from bottom i want the next five records . Please help . Thanks in Advance;

我正在使用此查询来获取下五个记录

I am using this query for fetching next five records

ref_to_all_posts.orderByChild("negative_timestamp").startAt( neg_timeStamp).limitToFirst(5)

推荐答案

您需要存储时间戳 和页面最后一项的键.然后,您可以使用以下页面获取下一页:

You'll need to store the timestamp and the key of the last item of the page. Then you can get the next page with:

ref_to_all_posts
  .orderByChild("negative_timestamp")
  .startAt(lastTimeStamp, lastKey)
  .limitToFirst(6)

这里要注意两件事:

  • 我传递了 timestamp 和上一页最后一项的键.Firebase数据库使用这些来查找该项目作为此查询的起点.
  • 我们请求6个项目,因为查询也将返回相同的项目.无法阻止返回此重叠项,因此您必须将其过滤出客户端.
  • I pass in the timestamp and the key of the last item on the previous page. The Firebase Database uses these to find the item as the starting point for this query.
  • We request 6 items, since the query will also return the same item. There is no way to prevent returning this overlapping item, so you have to filter it out client-side.

这篇关于Android中的Firebase分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆