Jas1997 Jas1997 - 15 days ago 6
Java Question

Sorting firebase objects based on long values on android

I am currently working on an android app that shows times/dates for rides to and from certain locations. I want to sort my firebase objects so that objects are sorted based on date. I tried searching online and playing with the methods

ref.setPriority(...)
, and
ref.orderByChild(...)
, but I cannot find a clear way on doing this.

This is what my database looks like currently

This is what my database looks like currently

I have the date in a
long
data type, and I want my firebase recycler view to show the rides in ascending order, in terms of how soon the ride is from the current date. Thanks!

Answer

You can query like this:

Query query = mRideRef.orderByChild("date");

And then set a listener to get the values