• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Firebase & RecyclerView

Ratchoss

Newbie
Hello, i'm new there.

I have a trouble with my app, i made a RECYCLERVIEW with my firebase data as items, but i would like to filter it.

I want to hide any data that has "connected: off" from the recyclerview list.
upload_2017-10-24_10-4-35.png


however, I want to display all the data that has "connected: on"
upload_2017-10-24_10-6-49.png


Here is my code that will help you in this process, I want to filter the "on" and "off", hide the "off" and display the "on".

Java:
        FirebaseRecyclerAdapter<Films,FilmsViewHolder> adapter = new FirebaseRecyclerAdapter<Films, FilmsViewHolder>(
                Films.class,
                R.layout.salonview,
                FilmsViewHolder.class,
                //referencing the node where we want the database to store the data from our Object
                mDatabaseReference.child("Salons").getRef()
        ) {
            @Override
            protected void populateViewHolder(FilmsViewHolder viewHolder, final Films model, int position) {
....

Thank you for helping me.
 
Hi there. The code you've shown is not enough. Ideally we want to see what's in the "...." section. i.e. what's the structure of your items (Films?) that you're adding to the list.
I'm guessing you need some logic in the populateViewHolder() method, to determine the value of the 'connected' property.
 
Oh sorry!

That's the code for the "Salons Class" :
Java:
        if (recycle != null) {
            //to enable optimization of recyclerview
            recycle.setHasFixedSize(true);
        }
        //using staggered grid pattern in recyclerview
        mLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
        recycle.setLayoutManager(mLayoutManager);

        //Say Hello to our new FirebaseUI android Element, i.e., FirebaseRecyclerAdapter
        FirebaseRecyclerAdapter<Films,FilmsViewHolder> adapter = new FirebaseRecyclerAdapter<Films, FilmsViewHolder>(
                Films.class,
                R.layout.salonview,
                FilmsViewHolder.class,
                //referencing the node where we want the database to store the data from our Object
                mDatabaseReference.child("Salons").getRef()
        ) {
            @Override
            protected void populateViewHolder(FilmsViewHolder viewHolder, final Films model, int position) {
                viewHolder.tvFilmsName.setText(model.getEntreprise());
                viewHolder.tvFilsAdresse.setText(model.getAdresse());
                Picasso.with(Salons.this).load(model.getURL()).into(viewHolder.ivFilmsPoster, new Callback() {
                    @Override
                    public void onSuccess() {
                        pd.dismiss();
                    }

                    @Override
                    public void onError() {

                    }
                });
                viewHolder.ivFilmsPoster.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        entreprise.clear();
                        image.clear();
                        entreprise.add(model.getEntreprise());
                        image.add(model.getURL());

                        startActivity(new Intent(Salons.this, ProfileSalons.class));
                    }
                });

            }
        };

        recycle.setAdapter(adapter);

The "Films class" :

Java:
public class Films {
    public String entreprise;
    public String gerant;
    public String adresse;
    public String fixe;
    public String portable;
    public String mail;
    public String mdp;
    public String photo;
    public String connected;

    public Films(){

    }
    public Films(String entreprise, String gerant, String adresse,String fixe, String portable, String mail, String mdp, String photo, String connected){
       this.entreprise = entreprise;
        this.gerant = gerant;
        this.adresse = adresse;
        this.fixe = fixe;
        this.portable = portable;
        this.mail = mail;
        this.mdp = mdp;
        this.photo = photo;
        this.connected = connected;
    }

    public String getEntreprise() {
        return entreprise;
    }

    public void setEntreprise(String entreprise) {
        this.entreprise = entreprise;
    }


    public String getGerant() {
        return gerant;
    }

    public void setGerant(String gerant) {
        this.gerant = gerant;
    }

    public String getAdresse() {
        return adresse;
    }

    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    public String getFixe() {
        return fixe;
    }

    public void setFixe(String fixe) {
        this.fixe = fixe;
    }

    public String getPortable() {
        return portable;
    }

    public void setPortable(String portable) {
        this.portable = portable;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getMdp() {
        return mdp;
    }

    public void setMdp(String mdp) {
        this.mdp = mdp;
    }

    public String getURL() {
        return photo;
    }

    public void setURL(String photo) {
        this.photo = photo;
    }


    public String getConnected() {
        return connected;
    }

    public void setConnected(String connected) {
        this.connected = connected;
    }


}

Sorry for neglecting some points about this problem. You have the necessary classes I think? Thank you in advance.
 
Thanks, that's a lot better.
So this is the interesting piece of code, but something I'm not really familiar with

Code:
                Picasso.with(Salons.this).load(model.getURL()).into(viewHolder.ivFilmsPoster, new Callback() {
                    @Override
                    public void onSuccess() {
                        pd.dismiss();
                    }

                    @Override
                    public void onError() {

                    }
                });

I don't know what 'Picasso' is, but it appears to be populating your viewHolder with data from the database?
So my question is, what is 'ivFilmsPoster'? Is it a list?
And I would imagine that your onSuccess() method is called when the data is loaded successfully. My thought is that you can iterate through the loaded data, and remove the items which have a connected value of "false".
 
I don't know what 'Picasso' is, but it appears to be populating your viewHolder with data from the database?

Oh, Picasso allows you for hassle-free image loading in your application, it's better use.

So my question is, what is 'ivFilmsPoster'? Is it a list?

ivFilmsPoster is the "ImageView" which "model.getURL()" is his URL LINK. So it's not a list.

This bellow is at the end of my "Salons class" :
Java:
    public static class FilmsViewHolder extends RecyclerView.ViewHolder{

        TextView tvFilmsName, tvFilsAdresse;
        ImageView ivFilmsPoster;

        public FilmsViewHolder(View v) {
            super(v);
            tvFilmsName = (TextView) v.findViewById(R.id.tv_name);
            tvFilsAdresse = (TextView) v.findViewById(R.id.tv_adresse);
            ivFilmsPoster = (ImageView) v.findViewById(R.id.iv_movie_poster);
        }
    }

And I would imagine that your onSuccess() method is called when the data is loaded successfully. My thought is that you can iterate through the loaded data, and remove the items which have a connected value of "false".

Oh, good idea, but how can i do this? (Checking if loaded data which have a connected value of "false" and hide it) please.

Thanks a lot for your help.
 
There is still not enough code shown. Please show the entire code for your list adapter class.
 
There is still not enough code shown. Please show the entire code for your list adapter class.

Okay, my bad!

There is it:
Salons.java
Java:
public class Salons extends AppCompatActivity {

    //created for firebaseui android tutorial by Vamsi Tallapudi

    private StaggeredGridLayoutManager mLayoutManager;

    //Getting reference to Firebase Database
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference mDatabaseReference = database.getReference();

    RecyclerView recycle;

    ProgressDialog pd;

    int pos;

    List<String> ItemsIntoList;

    public static List<String> coiffures = new ArrayList<String>();

    DatabaseReference myRef;

    public static List<String> naming = new ArrayList<String>();

    public static List<String> entreprise = new ArrayList<String>();
    public static List<String> image = new ArrayList<String>();

    public static List<String> listing = new ArrayList<String>();
    public static List<String> balayage = new ArrayList<String>();
    public static List<String> coloration = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_salons);

        recycle = (RecyclerView) findViewById(R.id.my_recycler_view);

        naming.clear();

        pd = new ProgressDialog(this);
        pd.setMessage("Chargement...");
        pd.show();
        pd.setCancelable(false);
        pd.setCanceledOnTouchOutside(false);

        if (recycle != null) {
            //to enable optimization of recyclerview
            recycle.setHasFixedSize(true);
        }
        //using staggered grid pattern in recyclerview
        mLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
        recycle.setLayoutManager(mLayoutManager);

        //Say Hello to our new FirebaseUI android Element, i.e., FirebaseRecyclerAdapter
        FirebaseRecyclerAdapter<Films,FilmsViewHolder> adapter = new FirebaseRecyclerAdapter<Films, FilmsViewHolder>(
                Films.class,
                R.layout.salonview,
                FilmsViewHolder.class,
                //referencing the node where we want the database to store the data from our Object
                mDatabaseReference.child("Salons").getRef()
        ) {
            @Override
            protected void populateViewHolder(FilmsViewHolder viewHolder, final Films model, int position) {
                viewHolder.tvFilmsName.setText(model.getEntreprise());
                viewHolder.tvFilsAdresse.setText(model.getAdresse());
                Picasso.with(Salons.this).load(model.getURL()).into(viewHolder.ivFilmsPoster, new Callback() {
                    @Override
                    public void onSuccess() {
                        pd.dismiss();
                    }

                    @Override
                    public void onError() {

                    }
                });
                viewHolder.ivFilmsPoster.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        entreprise.clear();
                        image.clear();
                        entreprise.add(model.getEntreprise());
                        image.add(model.getURL());

                        startActivity(new Intent(Salons.this, ProfileSalons.class));
                    }
                });

            }
        };

        recycle.setAdapter(adapter);

    }
    //ViewHolder for our Firebase UI
    public static class FilmsViewHolder extends RecyclerView.ViewHolder{

        TextView tvFilmsName, tvFilsAdresse;
        ImageView ivFilmsPoster;

        public FilmsViewHolder(View v) {
            super(v);
            tvFilmsName = (TextView) v.findViewById(R.id.tv_name);
            tvFilsAdresse = (TextView) v.findViewById(R.id.tv_adresse);
            ivFilmsPoster = (ImageView) v.findViewById(R.id.iv_movie_poster);
        }
    }
 
It's simple : I would like to show only data which have "connected : true" as child. and all other data which have "connected: false" will be hided.

TIP : I know how to remove an item from the RecyclerView = viewHolder.itemView.setVisibility(View.GONE);

Now my problem is i want to check if X has "connected:true" as child.

Thanks.
 
Back
Top Bottom