Cannot Perform Multiple Queries On Firebase Database to Display in RecyclerView

随声附和 提交于 2019-12-11 00:19:28

问题


I am trying to query the most recent children in my Firebase database and then sort that limit of recent children by a child value. I understand that the Cloud Firestore has recently been released, and that querying features continue to evolve on the Firebase Realtime Database as well.

I am using the FirebaseUI FirebaseRecyclerAdapter, and within that adapter you must enter a query. I am tweaking to add 2 queries to my RecyclerView. I am doing so as follows:

mFireAdapter = new FirebaseRecyclerAdapter<Poll, PollHolder>(
    Poll.class, R.layout.latest_item, PollHolder.class, 
    mBaseRef.child("Polls").limitToLast(3).orderByChild("vote_count"))

Unfortunately, it is not working, as it is first ordering the whole database by the child value and then displaying those 5 values. Essentially, the result is flipped in terms of what I am seeking: I want to query by limiting to the most recent X children and THEN sort those by child value. Any ideas where I am going wrong?

Edit:

Here is my Firebase Database. Essentially, I want to limit the query to the last 3 items in that database, and then sort those 3 items by vote count. I then want them to populate the RecyclerView accordingly. I am trying to do that in the code snippet listed above, but instead of actually limiting to the last 3 items in the database it is querying the whole database.

来源:https://stackoverflow.com/questions/42016194/cannot-perform-multiple-queries-on-firebase-database-to-display-in-recyclerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!