Anthony Anthony - 1 year ago 245
Java Question

How reverse the data fetched with FirebaseUI-Android?

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 ?

Answer Source

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 = new LinearLayoutManager(getActivity());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download