Picasso does not load cache image in listview

I use Picasso to upload images on my Listview extension, but it seems that image caching does not work.

I have a bunch of images on my list, and every time I scroll up and down, I see notes. I used to use Universal Image Loader, and it did not show me the placeholder when I already uploaded the image.

Here is my adapter and how I use it:

...

@Override
public View getChildView(int groupPosition, int childPosition, boolean b, View convertView, ViewGroup viewGroup) {
    final ChildViewHolder viewHolder;
    mChild = (ArrayList<Item>) mChildWrapper.get(groupPosition);
    Item item = mChild.get(childPosition);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.my_child_row, null);
        viewHolder = new ChildViewHolder();
        viewHolder.myImage = (ImageView) convertView.findViewById(R.id.my_img);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ChildViewHolder) convertView.getTag();
    }

    Picasso.with(mContext)
            .load(item.getUrl())
            .placeholder(R.drawable.my_placeholder)
            .into(viewHolder.myImage, new Callback() {
                @Override
                public void onSuccess() {
                    viewHolder.myImage.setVisibility(View.VISIBLE);
                }

                @Override
                public void onError() {
                    viewHolder.myImage.setVisibility(View.GONE);
                }
            });

    return convertView;
}

...

static class ChildViewHolder {
    ...
    private ImageView myImage;
    ...
}

I referenced this post for caching, but it didn't work for me. What am I doing wrong here?

+4
source share

No one has answered this question yet.


All Articles