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
Update: This is extremely bad practice and very glitchy. I HIGHLY discourage ANYONE to use this since it will make your RecyclerView very glitchy and will cause excess data loading, which is NOT what your users want.
I ended up making it manually as so:
if(x)
viewHolder.itemView.setVisibility(View.GONE); //itemView is a view provided by Android, no need to initiate it.
This says, if x
is true
, get the row and set its visibility to GONE
. This solved the problem for me. I will probably fork this on GitHub.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With