我正在使用Firebase开发一个类似tweeter的应用,但我仍然坚持一些观点。在新闻源页面中,我必须获取用户时间轴对象。但是,整理一次并将所有tem添加到列表视图中并不是一个好方法。我想我必须实施两件事;
有很多方法可以实现1.但是,我不知道有什么方法可以通过scrool视图从Firebase(limittolast除外)获取部分数据。例如;我想加载10个项目列表,当用户滚动时,Firebase将按照主题加载下一个项目。有没有办法以有效的方式将这两者结合起来?
答案 0 :(得分:1)
我认为你想通过无休止的滚动来实现分页
您需要通过设置index
属性然后按顺序来调整数据结构来处理它。
这是一个简单的例子:
"users": {
"mehdi": {
"index" : 0,
"first_name": "Mehdi",
"last_name": "Sakout"
},
"jhon": {
"index" : 1,
"first_name": "Jhon",
"last_name": "Doe"
},
"lahbib": {
"index" : 3,
"first_name": "Lahbib",
"last_name": "Anik"
}
}
你的java代码
int itemsPerPage = 5;
int currentPage = 0;
myDatabaseReference.orderByChild("index").startAt(itemsPerPage*currentPage).limitToLast(itemsPerPage)
答案 1 :(得分:1)
其实我在以下链接中找到了答案https://medium.com/@GiacomoRebonato/i-get-your-example-and-i-hoped-that-i-could-do-it-in-i-different-way-6c3a254bb359#.w11amv63z 该教程说,首先你得到101项,并使用最后一项查询下一个查询:
myDatabase.child("timeline").child(user.getUid()).orderByKey().endAt(lastLoadedItemKey).limitToLast(itemNumberToBeLoaded);
我正在使用时间轴对象的push()键。