Picasso does not work with Recycler View in android

Have you seen this article? It's about RecyclerView. Author uses Picasso in adapter.

@Override
public void onBindViewHolder(FeedListRowHolder feedListRowHolder, int i) {
    FeedItem feedItem = feedItemList.get(i);

    Picasso.with(mContext).load(feedItem.getThumbnail())
            .error(R.drawable.placeholder)
            .placeholder(R.drawable.placeholder)
            .into(feedListRowHolder.thumbnail);

    feedListRowHolder.title.setText(Html.fromHtml(feedItem.getTitle()));
}

I had the same issue when I wanted to load an image from its URL with API in extended RecyclerView.Adapter and RecyclerView.ViewHolder.

First of all, you must check the URL might not be empty or null and then load it with Picasso.

@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
      RssItem item = rssItems.get(i);
      if(item.imageLink!=null && !item.imageLink.isEmpty()) {
          Picasso.with(F.context)
              .load(item.imageLink)
              .placeholder(R.drawable.default_placeholder)
              .error(R.drawable.error_placeholder)
              // To fit image into imageView
              .fit()
              // To prevent fade animation
              .noFade()
              .into(viewHolder.postImage);
     } else {  
          viewHolder.postImage.setImageDrawable(ContextCompat.getDrawable(F.context,R.drawable.default_placeholder));
     }
     viewHolder.postTitle.setText(item.title);
     viewHolder.postAuthor.setText(item.postWriter);
     viewHolder.postDate.setText(item.pubDate);
}

At last you must be aware of viewHolder.postImage and how it's found. It might be null or not finded view by id correctly.


use just a simple code:

 @Override
    public void onBindViewHolder(ShivaViewholder holder, int position) {
    Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(holder.imageView2);
    }

But if you also want the image in icon, or want the location then we will use some additional code in this code.