如何从recyclerview中的Firebase数据库中从下到上检索数据,或者如何在Firebase中的数据库顶部添加数据? [英] How to retrieve data from bottom to top from Firebase database in recyclerview or how to add data at the top of database in Firebase?

查看:125
本文介绍了如何从recyclerview中的Firebase数据库中从下到上检索数据,或者如何在Firebase中的数据库顶部添加数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Firebase数据库的应用程序。我正在接收数据并上传它没有问题,但我想添加我的数据在数据库数组的顶部,而不是在数据库数组的底部。

<所以建议我可以帮助我从底部到顶部检索数据的东西,或者我可以上传到我的数据库数组的顶部。提前致谢。请帮助我。

解决方案

有几种方法可以做到这一点。

第一:

实现 FirebaseUI ,然后执行以下操作:

  LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); 
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager)

第二:



我更喜欢这种方式,特别是如果您计划在将来实现GridLayoutManager。注意,GridLayoutManager不支持 setStackFromEnd(); 。以下将允许您在AdapterView中反转任何数据。
$ b $ p在您的RecyclerViewAdapter中

$ $ $ $ $ @Override
public Item getItem(int pos){
return super.getItem(getCount() - 1 - pos);
}


I m developing an app with Firebase database. I'm receiving data and uploading it there is no problem in that, but I want to add my data on the top of database array, not at the bottom of database array.

So suggest me something which can help me to retrieve the data from bottom to the top or I can upload it to the top of my database array. Thanks in advance. Please help me out.

解决方案

There's a couple ways to do this.

First:

Implement FirebaseUI and then do the following:

LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager)

Second:

I prefer this way, especially if you plan to implement a GridLayoutManager in the future. Note, GridLayoutManager does not support setStackFromEnd();. The below will allow you to reverse any data in an `AdapterView.

In your RecyclerViewAdapter

@Override
public Item getItem(int pos) {
return super.getItem(getCount() - 1 - pos);
}

这篇关于如何从recyclerview中的Firebase数据库中从下到上检索数据,或者如何在Firebase中的数据库顶部添加数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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