How reverse the data fetched with FirebaseUI-Android?

醉酒当歌 提交于 2019-11-27 08:14:43

问题


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 ?

回答1:


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);


来源:https://stackoverflow.com/questions/33830387/how-reverse-the-data-fetched-with-firebaseui-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!