How to exclude an element from FirebaseRecyclerAdapter

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 delete the item if !dataSnapshot.hasChild(getUid()) is true , otherwise just keep filling the ViewHolder as usual. Please note: I do not want the item to be deleted from the database , I want it to disappear from the FirebaseRecyclerAdapter . What method is available for this?


Edit: I ALWAYS searched for a solution to this problem since it was not fixed . My decision is HIGHLY discouraged and very bad practice, and I changed my mind to use it myself.

+8
android firebase firebase-database firebaseui
source share
2 answers

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

There is currently no way to filter your client side of the results with FirebaseUI (however, I believe this is planned to be implemented in the future):
https://github.com/firebase/FirebaseUI-Android/issues/135

+2
source share

Update: This is a very bad practice and very buggy. I HIGHLY DISCLAIM ANYONE to use this, as this will make your RecyclerView very buggy and lead to overloading the data, which is NOT what your users want.

I ended up doing it manually:

 if(x) viewHolder.itemView.setVisibility(View.GONE); //itemView is a view provided by Android, no need to initiate it. 

This says that if x is true , get the string and set its visibility to GONE . This solved the problem for me. I will probably open this on GitHub.

+1
source share

All Articles