I was wondering If new firebase database has added this capability because I need it in my project..
The structure looks like this..
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With