7

I was wondering If new firebase database has added this capability because I need it in my project..

The structure looks like this..

enter image description here

and ya setting RecyclerView to reverse wont work for me because that cause it cause it to start from bottom.

Solution

So, This is the best solution i can possibly think of..For now.

As @Frank said this could be the duplicate but I solved it initially with his help.

so What we can do is Make the timeStamp negative i.e -20164846476589

and then Subtracting it with Some higher value like 999999999999999L (which for now we are not going to exceed offcourse) and then what we get Would be the lowest descending value for new Timestamp

and the data would automagically will be descending in Firebase

ie

 String NewDescTimeStamp= String.valueOf((9999999999999L+(-1 * PreviousTimestamp)));

 mFirebaseRef.child(NewDescTimeStamp).setValue(true);
Jongware
  • 22,200
  • 8
  • 54
  • 100
Sahaj Rana
  • 1,993
  • 4
  • 25
  • 42
  • 1
    This has been covered many times already. You'll either have to reverse the results client-side or add a property with an inverted value to your data. See [this answer](http://stackoverflow.com/questions/34156996/firebase-data-desc-sorting-in-android/34158197#34158197) or any of the [results in this list](http://stackoverflow.com/search?q=%5Bfirebase-database%5D+descending) – Frank van Puffelen Jul 11 '16 at 14:33
  • http://stackoverflow.com/a/42572025/2149195 – RBK Mar 03 '17 at 06:24

1 Answers1

14

You can't do that with the existing API.

You can use one or more of the following methods to retrieve a known number of children: limitToFirst(), limitToLast(), startAt(), endAt()

also you can use one of the ordering methods: orderByChild(), orderByValue() , orderByKey()

Than, Store them in a data structure (Such as ArrayList) and then Use java.util.Collections.reverse() to reverse the list.

With firebase you should do some of the query logic client side. Not all operations available in SQL are available on Firebase.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
TomerBu
  • 1,483
  • 15
  • 15