AbAppletic AbAppletic - 1 year ago 114
Android Question

How to exclude item from a FirebaseRecyclerAdapter

I have this code in my


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() {
public void onDataChange(DataSnapshot dataSnapshot) {
if (!dataSnapshot.hasChild(getUid())) {

public void onCancelled(DatabaseError databaseError) {

//...Populating the viewholder...

I want to remove the item if
, 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
. 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.

Answer Source

I ended up making it manually as so:

   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.

Edit: 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download