简体   繁体   English

Android Studio FirebaseRecyclerAdapter仅过滤一次

[英]Android Studio FirebaseRecyclerAdapter Filter Only Once

I am making an app and I am having a problem displaying items in my recyclerview. 我正在制作一个应用程序,但在recyclerview中显示项目时遇到问题。 I am displaying items with the following configuration in my FirebaseRecyclerAdapter, 我在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. 如您所见,我正在按票数对recyclerview中的每个项目进行排序。 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. 问题是,当用户对某个项目进行投票时,它将缩放至顶部,因为我已将其设置为按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"); 然后,我想删除过滤器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. 我试图改变OrderByVotesOnPopulateViewHolder ,但它不工作。 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. 首先,我制作了feedRef的副本,并按displayvotes的顺序使用了该副本,同时每次每次投票赞成或反对时仍更新feedRef。 I displayed the votes with my clone database reference, allowing me to vote without movement of items yet still display the votes accordingly. 我在克隆数据库引用中显示了投票,这使我可以在不移动项目的情况下进行投票,但仍会相应显示投票。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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