Hey there,
@pautena and I are developing an Android app with a Firebase backend at Hack The North 2016.
We've faced this problem and we think that could be nice to solve with a new feature in future versions:
mFirebaseDatabaseReference.child(User.USER_CHILD).orderByChild("points") to make a ranking, but we faced the problem that Firebase only retrieves the ordered data in ascendent mode.We think that would be awesome to have the possibility to query orderByChild with some kind of parameter which indicates if you want your data ordered in an ascendent or descendent way.
We post this issue to stay tuned for improvements in this area and hope Firebase become even more cool! :D
See #90, it should solve your issue.
Yeah, @SUPERCILEX, we saw this issue like 30 minutes ago, it's effective, but I'm sure Firebase can give us a cleaner and smother way in the future.
Thank you anyway for the help :)
We've found a good solution if you're using the DatabaseReference to populate a FirebaseRecyclerAdapter, here it goes:
@Override
public User getItem(int position) {
return super.getItem(getItemCount() - 1 - position);
}
Hope it helps anybody with the same problem :D
Oooho.... that's a neat trick Andreu!
On Sat, Sep 17, 2016 at 5:28 PM Andreu RodrÃguez i Donaire <
[email protected]> wrote:
We've found a good solution if you're using the DatabaseReference to
populate a FirebaseRecyclerAdapter, here it goes:
- Inside the FirebaseRecyclerAdapter declaration, override the
getItem() function just like we did:@Override
public User getItem(int position) {
return super.getItem(getItemCount() - 1 - position);
}Hope it helps anybody with the same problem :D
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/firebase/FirebaseUI-Android/issues/310#issuecomment-247816246,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA3w3yP44_uY5yw2-O2AnNBFbzfkt3mjks5qrIW-gaJpZM4J_v_-
.
The problem with your original request is that it requires a change to the Firebase SDK. While that is a valid request (and I'll use it to remind our engineers of the demand for this feature), it is unrelated to FirebaseUI. I'm closing the issue here, but must admit that your workaround is embarrassingly simple. We should've thought of that one earlier. :-)
This will work ok if you are returning the entire search query - I believe you hit problems when you limit the range that you are returning using limitToFirst(); In my case I'm trying to return the highest 100 scores based on a child, but if the query returns more than 100, then I get the lowest 100 ranked in the correct order.
To solve this, I had to store the negated (negative) score and use the ascending sort. This also requires that I comment out the following from the example code, otherwise the results are flipped (top 100, but lowest to highest).
// manager.setReverseLayout(true);
// manager.setStackFromEnd(true);
Hope this helps.
The problem with @anrodon's solutions is that now the list is not updated automatically when new data is added. However, It works when I do the query again.
@Shajeel-Afzal it's true.it's not work when new data updated to the database.
But,Great work dude...
I Found a solution to solve the issue on firebase recycler view as reported by @Shajeel-Afzal .
After doing the solution of @anrodon just override another firebase recycler method onDataChange as
below,
@Override
public void onDataChanged() {
recycle.removeAllViews();
super.onDataChanged();
}
now you will get real time updation of items in recycler view.
Hi Suhailakl, could you better explain where this code should be included? I can not make it work. Thank you.
Most helpful comment
We've found a good solution if you're using the DatabaseReference to populate a FirebaseRecyclerAdapter, here it goes:
Hope it helps anybody with the same problem :D