如何从FirebaseRecyclerAdapter中排除项目 [英] How to exclude item from a FirebaseRecyclerAdapter

查看:217
本文介绍了如何从FirebaseRecyclerAdapter中排除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 populateViewHolder 中有这样的代码:

  public void populateViewHolder(最终CampaignHolder viewHolder,最终Campaign广告系列,final int位置){
String k = getRef(position).getKey();
ref.child(k).child(users)。addListenerForSingleValueEvent(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
if(! dataSnapshot.hasChild(getUid())){
// Something ...
}
}
$ b $ @Override
public void onCancelled(DatabaseError databaseError ){

}
});
// ...将人物视为人物...

我想移除物品如果!dataSnapshot.hasChild(getUid()) true,否则继续正常填充ViewHolder。请注意,我不想从数据库中删除项目,我只希望它从 FirebaseRecyclerAdapter 中消失。什么方法可以做到这一点?






编辑:我仍然在寻找解决方案对于这个问题,因为没有被修复。我的解决方案是非常不鼓励和非常糟糕的做法,我已经重新考虑使用它自己。

解决方案

最佳做法是使用服务器端过滤:
https://firebase.google.com/目前无法用FirebaseUI过滤客户端的结果(不过我相信计划在未来实施):


https://github.com/firebase/FirebaseUI-Android/issues/135


I have this code in my populateViewHolder:

public void populateViewHolder(final CampaignHolder viewHolder, final Campaign campaign, final int position) {
            String k = getRef(position).getKey();
            ref.child(k).child("users").addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (!dataSnapshot.hasChild(getUid())) {
                       //Something...
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
            //...Populating the viewholder...

I want to remove the item if !dataSnapshot.hasChild(getUid()) is true, otherwise just keep on populating the ViewHolder normally. Note that I don't want to remove the item from the database, I only want it gone from the FirebaseRecyclerAdapter. What method is available for doing this?


Edit: I am STILL looking for a solution for this problem as it has not been fixed. My solution is HIGHLY discouraged and very bad practice, and I have reconsidered using it myself.

解决方案

Best practice would be to use server side filtering: https://firebase.google.com/docs/database/android/retrieve-data#sorting_and_filtering_data

At the moment there is no way to filter your results client side with FirebaseUI (however I do believe it is planned to be implemented in the future):
https://github.com/firebase/FirebaseUI-Android/issues/135

这篇关于如何从FirebaseRecyclerAdapter中排除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆