如何反转用FirebaseUI-Android获取的数据? [英] How reverse the data fetched with FirebaseUI-Android?

查看:124
本文介绍了如何反转用FirebaseUI-Android获取的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用FirebaseUI-Android库简单地在回收视图中显示数据集。

数据存储在Firebase中的列表中,这要归功于push()方法。

当我得到数据时,我得到了最早的数据,而我的要求是最年轻的。所以我需要一个相反的顺序。


  1. 有没有办法用FirebaseUI来做到这一点?


  2. 使用Firebase Core,似乎只有两种可能的方法(从):
    $ b



适配器级别,作为Firebase拉对象的整个列表。



对于RecyclerView,这里是一个解决方案。 mL $ outoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setReverseLayout(true); //这也设置setStackFromBottom为true
// mLayoutManager.setStackFromEnd(true);
mRecyclerView.setLayoutManager(mLayoutManager);


I try to use the FirebaseUI-Android lib to simply display a data set in a recycler-view.

Data are store in Firebase in a list, thanks to push() method.

When I get the data, I got the oldest data first, and my requirement is the youngest first. So I need a reverse order.

  1. Is there a way to do that with FirebaseUI itself?

  2. With Firebase Core, it seems the 2 only possible ways are (from Display posts in descending posted order) :

    • getting all the data, and revert them at runtime (in Force), thanks to @Kato snippet
    • setting a decreasing priority for every item push in the list at writing time. This require we know every (today and tomorrow) ordering usage at startup of data pull creation. This is often not the case. Is there any other (old or new) option to do this simple and main frame job ?

解决方案

This should be done at adapter level, as Firebase pull the whole list of object.

For a RecyclerView, here is a solution.

mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setReverseLayout(true); // THIS ALSO SETS setStackFromBottom to true
// mLayoutManager.setStackFromEnd(true);
mRecyclerView.setLayoutManager(mLayoutManager);

这篇关于如何反转用FirebaseUI-Android获取的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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