Search code examples
androidfirebase-realtime-databasefirebaseui

Firebase RecyclerOptions not retreiving data from firebase


I am trying to retrieve some data to add to a placeholder but can't do it. And I Cant find where the problem is.

I searched from every where and I did some debug. I found the the problem may be lying in the firebaseRecyclerOptions that does not load the data from firebase to my models.

I initiate the database like this:

//Init FIrebase
    database = FirebaseDatabase.getInstance();
    kwot = database.getReference().child("Kwot");

This is where i retreive the data

private void loadKwot() {
    FirebaseRecyclerOptions<Kwot>  options =
            new FirebaseRecyclerOptions.Builder<Kwot>()
            .setQuery(kwot,Kwot.class)
                    .build();
    adapter = new FirebaseRecyclerAdapter<Kwot, KwotViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull KwotViewHolder holder, int position, @NonNull Kwot model) {
            //Ici on va charger les pensee et image des kwot sur firebase
            //Pour faciliter les choses on ne charge pas les pensee, on laisse
            //ainsi la pensee par défaut qui est dans le string

                index ++;
            //Chargement de l'image avec Picasso
            Picasso.get().load(model.getImgUrl())
                    .into(holder.imageViewKwot);
            final Kwot clickItem = model;
            holder.setItemClickListener(new ItemClickListener() {
                @Override
                public void onCLick(View view, int position, boolean isLongCLick) {
                    Toast.makeText(Home.this, "Item Clicked", Toast.LENGTH_SHORT).show();
                }
            });

        }

        @NonNull
        @Override
        public KwotViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            View itemView = LayoutInflater.from(getBaseContext())
                    .inflate(R.layout.kwot_item,viewGroup,false);
            return new KwotViewHolder(itemView);
        }
    };
    recycler_kwot.setAdapter(adapter);
}

@Override
protected void onStart() {
    super.onStart();
    adapter.startListening();
}

@Override
protected void onStop() {
    super.onStop();
    adapter.stopListening();
}

Here is the Model

public class Kwot {
    private String categorie;
    private String description;
    private String imgUrl;
    private String pensee;


public Kwot() {
}

public Kwot(String imgUrl, String description, String categorie, String pensee) {
    this.imgUrl = imgUrl;
    this.description = description;
    this.categorie = categorie;
    this.pensee = pensee;
}



public String getImgUrl() {
    return imgUrl;
}

}

enter image description here

I expect to have some data in my recycler view, but it seems that it does not work


Solution

  • Found the solution. It appears that my recyclerView height was wrap_content instead of match_parent.