Search code examples
androidandroid-recyclerviewpicasso

Picasso failed to setImage on CircleImageView on a recyclerview


I was trying to load data from firebase into my recycler view. There are two values that I am retrieving first is Name and second is the ImageUrl. When i run my app the value from the name is displaying on the recyclerview but the image is still blank. Somehow picasso is failing to load the image into the CircleImageView.

Below is my ViewHolderclass

public static class CategoryViewHolder extends RecyclerView.ViewHolder {

View mView;
CircleImageView categoryImageView;
TextView categoryName;

public CategoryViewHolder(View itemView) {
    super(itemView);

    mView = itemView;

}

public void setDisplayName(String name){

     categoryName = (TextView) mView.findViewById(R.id.Category_name);
    categoryName.setText(name);

}


public void setUserImage(String thumb_image, Context ctx){

    categoryImageView = (CircleImageView) 
mView.findViewById(R.id.Category_pic);



 Picasso.with(ctx).load(thumb_image).placeholder(R.drawable. 
   default_avatar)
 .into( categoryImageView);
 //   Picasso.with(ctx) .load(thumb_image)  .into(categoryImageView);
}


 }

this is my model class

public class CategoryItems {
private  String Name;
private String ImageUrl;

public CategoryItems(String title, String imageURL) {
this.Name = title;
this.ImageUrl = imageURL;
}


publ  ic CategoryItems(){

                   }

public String getName() {
return Name;
}

 public void setName(String name) {
Name = name;
}

public String getImageUrl() {
return ImageUrl;
}

 public void setImageUrl(String imageUrl) {
ImageUrl = imageUrl;
}
}

this is my FirebaseREcyclerViewAdapter

public void onStart() {
super.onStart();
startListening();
}

 public void startListening(){
  Query query = FirebaseDatabase.getInstance()
        .getReference()
        .child("Catlist")
        .limitToLast(500);

    FirebaseRecyclerOptions<CategoryItems> options =
        new FirebaseRecyclerOptions.Builder<CategoryItems>()
                .setQuery(query, CategoryItems.class)
                .build();
   FirebaseRecyclerAdapter adapter = new 
   FirebaseRecyclerAdapter<CategoryItems, CategoryViewHolder>(options) {
    @Override
    public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int 
  viewType) {


        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.category_items, parent, false);



        return new CategoryViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(final CategoryViewHolder holder, int 
   position, final CategoryItems model) {

        holder.setDisplayName(model.getName());
        holder.setUserImage(model.getImageUrl(), getContext());
     //   holder.setUserStatus(model.getStatus());
        Log.d(model.getImageUrl().toString(), "onBindViewHolder: ");


    }
};
mUsersList.setAdapter(adapter);
adapter.startListening();
}

my recycler is displaying names only and i tried to log the imageurls and its displaying the url fine


Solution

  • Try enabling logging in Picasso to look at errors and warning, it will definitely show some error in your case which you can resolve.

    Picasso  
    .with(context)
    .setLoggingEnabled(true)
    ....
    

    For more information check out this link