Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 774
Jas1997 Avatar asked Mar 21 '26 23:03

Jas1997


2 Answers

You can query like this:

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

And then set a listener to get the values

like image 133
Rosário Pereira Fernandes Avatar answered Mar 24 '26 11:03

Rosário Pereira Fernandes


Adding onto Rosario's answer, I just want to say after creating the query, just inject it into the firebase recycler adapter as the final parameter to get a sorted recycler view. Didn't realize that it had the option but it works perfectly now!

like image 40
Jas1997 Avatar answered Mar 24 '26 11:03

Jas1997



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!