0

I am using Picasso in a list adapter to load images asynchronously from URIs

Picasso.with(viewHolder.albumArt.getContext())
.load(songObject.albumArtURI)
.placeholder(R.drawable.grayalbumart)
.into(viewHolder.albumArt);

The problem is that the images aren't being loaded. I only see the placeholder images.

note: I am not loading URLs. I am loading URIs.

the_prole
  • 8,275
  • 16
  • 78
  • 163

4 Answers4

1

Use callbacks to know whether bitmap from your image is correctly loaded into your imageview.

you can use picasso's callback as below

Picasso.with(getContext())
    .load(url)
    .into(imageView, new com.squareup.picasso.Callback() {
                    @Override
                    public void onSuccess() {
                          // Log something here eg "true"
                    }

                    @Override
                    public void onError() {
                         // Log something here eg "false"
                    }
                });

Now if your bitmap is correctly loaded then true will be logged or else false. if its true then do not worry, it its false then check whether your url is correct or not.

Note:- make sure in the url which your receive from server, there are no spaces in file name otherwise it wont load, I myself have faced this issues many time, so just cross check for the names you receive.

karan
  • 8,637
  • 3
  • 41
  • 78
0

IF it is from drawable folder then:

uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"+context.getPackageName()+"/drawable/" + drawableName);

Picasso.with(viewHolder.albumArt.getContext())
.load(uri)
.placeholder(R.drawable.grayalbumart)
.into(viewHolder.albumArt);
vaibhav
  • 816
  • 9
  • 13
manishm
  • 71
  • 8
0

Answered my own question

if(songObject.albumArtURI != null){

        File f = new File(songObject.albumArtURI);

        Picasso.with(viewHolder.albumArt.getContext())
                .load(f)
                .placeholder(R.drawable.grayalbumart)
                .into(viewHolder.albumArt);
    } else {

        Picasso.with(viewHolder.albumArt.getContext())
                .load(songObject.albumArtURI)
                .placeholder(R.drawable.grayalbumart)
                .into(viewHolder.albumArt);
    }
the_prole
  • 8,275
  • 16
  • 78
  • 163
0

Try this,

I have added this code to my adapter

        String url = alist.get(position).getProfileImage();

        holder.ivPic.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Picasso.with(context).load(url).into(holder.ivPic);
Parth Bhayani
  • 1,894
  • 3
  • 17
  • 35