Я не могу заставить Пикассо работать с RecyclerView.Adapter
.Он загружает заполнитель, но не изображение из URL.
Активность
public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.NewsViewHolder> {
private List<News> mNews;
private Context mContext;
public NewsAdapter(List<News> mNews, Context mContext) {
this.mNews = mNews;
this.mContext = mContext;
}
@NonNull
@Override
public NewsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.news_list_item, parent, false);
return new NewsViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull NewsViewHolder holder, int position) {
News news = mNews.get(position);
holder.itemSection.setText(news.getmSectionName());
holder.itemDate.setText(news.getmWebPublicationDate());
holder.itemHeadline.setText(news.getmHeadline());
Picasso.get().load(news.getmThumbnail()).placeholder(R.drawable.ic_launcher_background).into(holder.itemThumbnail);
}
@Override
public int getItemCount() {
return mNews.size();
}
/**
* ViewHolder Class
*/
public class NewsViewHolder extends RecyclerView.ViewHolder {
public TextView itemSection;
public TextView itemDate;
public TextView itemHeadline;
public ImageView itemThumbnail;
public TextView itemContributor;
public NewsViewHolder(@NonNull View itemView) {
super(itemView);
itemSection = itemView.findViewById(R.id.news_item_section);
itemDate = itemView.findViewById(R.id.news_item_date);
itemHeadline = itemView.findViewById(R.id.news_item_headline);
itemThumbnail = itemView.findViewById(R.id.news_item_thumbnail);
itemContributor = itemView.findViewById(R.id.news_item_contributor);
}
}
}
Класс новостей
public class News {
private String mSectionName;
private String mWebPublicationDate;
private String mWebUrl;
private String mHeadline;
private String mThumbnail;
private String mWebTitle;
private String mPillarName;
public News(String mSectionName, String mWebPublicationDate, String mWebUrl, String mHeadline, String mThumbnail, String mWebTitle, String mPillarName) {
this.mSectionName = mSectionName;
this.mWebPublicationDate = mWebPublicationDate;
this.mWebUrl = mWebUrl;
this.mHeadline = mHeadline;
this.mThumbnail = mThumbnail;
this.mWebTitle = mWebTitle;
this.mPillarName = mPillarName;
}
public String getmSectionName() {
return mSectionName;
}
public String getmWebPublicationDate() {
return mWebPublicationDate;
}
public String getmWebUrl() {
return mWebUrl;
}
public String getmHeadline() {
return mHeadline;
}
public String getmThumbnail() {
return mThumbnail;
}
public String getmWebTitle() {
return mWebTitle;
}
public String getmPillarName() {
return mPillarName;
}
@Override
public String toString() {
return "News{" +
"mSectionName='" + mSectionName + '\'' +
", mWebPublicationDate='" + mWebPublicationDate + '\'' +
", mWebUrl='" + mWebUrl + '\'' +
", mHeadline='" + mHeadline + '\'' +
", mThumbnail='" + mThumbnail + '\'' +
", mWebTitle='" + mWebTitle + '\'' +
", mPillarName='" + mPillarName + '\'' +
'}';
}
}