Skip to content Skip to sidebar Skip to footer

Delete Data From Firebase Recycler View Adapter Without Deleting In The Database

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

Solution 1:

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.

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.

Solution 2:

And how about this in ViewHolder?

itemView.setOnClickListener(newView.OnClickListener() {
            @OverridepublicvoidonClick(View view) {
                itemView.setVisibility(View.INVISIBLE);
            }
        });

Solution 3:

Yes you can. You have to add this in your GameViewHolder class:

  1. Create a function and get reference of your cardview
  2. Create a layout params and Create an instance of the parent of your cardview then set the height and the width equals to 0

publicvoidRemove() {
    cardView = mView.findViewById(R.id.cardview);
    cardView.setLayoutParams(new FrameLayout.LayoutParams(0,0));
}
  1. Use the function

viewHolder.remove();

Post a Comment for "Delete Data From Firebase Recycler View Adapter Without Deleting In The Database"