Firebaseui-android: Order Firebase RecyclerView by Child Value

Created on 30 Jan 2017  Â·  9Comments  Â·  Source: firebase/FirebaseUI-Android

I have a data structure (see below) and I essentially want to create a "trending" section that emphasizes the items that have the most votes. Votes are accounted for in the vote_count field of my Firebase database.

I know there is the .orderByChild() method available in Firebase. Would it be possible to have my RecyclerView sort the data based on the value of the vote_count child (descending order)?

image

```

Most helpful comment

@jesusignazio setReverseLayout with your layout manager and then setstackfromend will do the descending order

All 9 comments

@troy21688 indexed or plain?

Can you elaborate Alex? I do not understand what you mean. Appreciate the
prompt response.

On Jan 30, 2017 4:13 PM, "Alex Saveau" notifications@github.com wrote:

@troy21688 https://github.com/troy21688 indexed or plain?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/firebase/FirebaseUI-Android/issues/557#issuecomment-276208624,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APuF-AshQvmK0gaBLpOinvWXiDrMUdNsks5rXmBugaJpZM4Lx7mW
.

Sorry, are you using the index adapters or just the plain ones (FirebaseIndexRecyclerAdapter vs FirebaseRecyclerAdapter)?

The plain adapter but believe I have my Pojo set up for index if necessary.

On Jan 30, 2017 5:14 PM, "Alex Saveau" notifications@github.com wrote:

Sorry, are you using the index adapters or just the plain ones (
FirebaseIndexRecyclerAdapter vs FirebaseRecyclerAdapter).

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/firebase/FirebaseUI-Android/issues/557#issuecomment-276222681,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APuF-GuJqze8rF6dptISxSLnh_oyB0X1ks5rXm7SgaJpZM4Lx7mW
.

@troy21688 No, that's good. Since you can pass in a query, just use orderByChild("vote_count") for the query/ref you pass into your adapter.

I believe @SUPERCILEX has the correct solution here so closing the issue.

@troy21688 in general it's better to post "how to" type questions on StackOverflow, issues here should be reporting instances where the library does not work as expected.

And what about to make data appear in descending order as he requested?
There is no inverted .orderByChild() function...

Edit: solution: here

@jesusignazio setReverseLayout with your layout manager and then setstackfromend will do the descending order

@karamJAB yes, I edited my message when I got the solution.

Thanks.

Was this page helpful?
0 / 5 - 0 ratings