Search code examples
androidlistviewandroid-imageviewpicasso

Picasso Image not always loading - Android


I am trying to set the ImageView to the image contained in the URL, it is done in the list adaptor class which loads an image for each item in list.

    Picasso.with(context).load("http://192.168.0.XX:8000"  + e.getImageURL()).into(eventImage);

I can see that the request is not always being sent to my local backend, but if I scroll the screen they might then load. The IP address and URLs are correct.


Solution

  • Use a listener to figure out the error or handle the case in which the image doesn't load,

    Picasso.Builder builder = new Picasso.Builder(context);
    
    builder.listener(new Picasso.Listener()
    {
        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception)
        {
            exception.printStackTrace();
        }
    });
    
    builder.build().load(imageUrl).placeholder(R.drawable.ic_placeholder).into(mImageView);