从Firebase Recycler View适配器删除数据而不在数据库中删除 [英] Delete data from firebase recycler view adapter without deleting in the database

查看:58
本文介绍了从Firebase Recycler View适配器删除数据而不在数据库中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就是这样,我可以从Firebase Recycler视图适配器中删除视图,但不能在数据库中删除吗?

That is it, can i remove a view from firebase recycler view adapter, but not deleting in the database?How?

 final FirebaseRecyclerAdapter<Game,GameViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<Game, GameViewHolder>(
            Game.class,
            R.layout.row,
            GameViewHolder.class,
            mdatabase

    ) {
        @Override
        protected void populateViewHolder(GameViewHolder viewHolder, Game model, final int position) {

            viewHolder.setTitle(model.getGame_name());
            viewHolder.setJugado(model.getJugado());
            viewHolder.setCreator(model.getCreator_name());

    recyclerView.setAdapter(firebaseRecyclerAdapter);


}

推荐答案

FirebaseRecyclerAdapter不支持此功能. FirebaseRecyclerAdapter的全部要点是,它与您最初为其指定的位置的内容保持同步.如果某件事从数据库中删除了数据,它将自动无条件地从您的适配器中删除.

FirebaseRecyclerAdapter doesn't support this. The whole point of FirebaseRecyclerAdapter is that it stays in sync with the contents of the location that you originally gave it. If something deletes data from the database, it will be automatically and unconditionally deleted from your adapter.

如果您想要这种行为,则必须实现自己的RecyclerView适配器,最好是不使用活动侦听器的适配器,以将数据位置的每次更改都通知给适配器.您将只需要听一次全部内容,然后将其发送到适配器以填充RecyclerView.

If you want this behavior, you will have to implement your own RecyclerView adapter, preferably one that does not use an active listeners to be notified of every change to the location of the data. You would have to listen to the entire contents just once, then send that to an adapter to populate a RecyclerView.

这篇关于从Firebase Recycler View适配器删除数据而不在数据库中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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