简体   繁体   中英

Android Studio FirebaseRecyclerAdapter Filter Only Once

I am making an app and I am having a problem displaying items in my recyclerview. I am displaying items with the following configuration in my FirebaseRecyclerAdapter,

firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<postsGetInfo, postsGetInfoViewHolder>(postsGetInfo.class, R.layout.posts_layout,postsGetInfoViewHolder.class,OrderByVotes) {

The problem that I am having is with my database reference,

 OrderByVotes = feedRef.child(current_user_id).orderByChild("displayvotes");

As you see, I am ordering each of the items in my recyclerview by the amount of votes. The problem is that when a user upvotes an item it will zoom to the top as I have set it to order by displayvotes. I want it to initially display the items in order of votes and then when a user upvotes the post for it to stay in the same place and not move around.

To Clarify:

  • I want the items to filtered by votes and displayed accordingly.

  • I then want to remove the filter, orderByChild("displayvotes");

  • Finally this will order the items initially and then will remove any filter.

I have tried changing OrderByVotes in the OnPopulateViewHolder but it doesn't work. If somebody can point me in the right direction that would be great, thanks!

For anyone reading this question, I have found a solution. It isn't perfect but it works. I firstly made a copy of the feedRef and used that copy to order by displayvotes while still updating the feedRef every time an item is up or down voted. I displayed the votes with my clone database reference, allowing me to vote without movement of items yet still display the votes accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM