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