由于某些错误,Picasso无法正常工作

时间:2018-04-24 01:09:56

标签: android picasso

我试图将我从JSON获得的网址转换为图片。我试图使用毕加索,但它给了我

错误:没有为into(int)找到合适的方法         。Picasso.get()负载(rssObject.getItems()得到(位置).getThumbnail()。)代入(R.id.imageView)。                                                                              ^     方法RequestCreator.into(Target)不适用       (参数不匹配; int无法转换为Target)     方法RequestCreator.into(ImageView)不适用       (参数不匹配; int无法转换为ImageView)

类FeedViewHolder扩展RecyclerView.ViewHolder实现View.OnClickListener,View.OnLongClickListener

这是我的代码,迫切需要快速帮助,谢谢

public TextView txtTitle,txtPubDate,txtContent,txtAuthor,txtThumbnail;
private ItemClickListener itemClickListener;
public ImageView imageView;



public FeedViewHolder(View itemView) {
    super(itemView);

    txtTitle=(TextView)itemView.findViewById(R.id.txtTitle);
    txtPubDate=(TextView)itemView.findViewById(R.id.txtPubDate);
    txtAuthor=(TextView)itemView.findViewById(R.id.txtAuthor);
    txtContent=(TextView)itemView.findViewById(R.id.txtContent);
    txtThumbnail=(TextView)itemView.findViewById(R.id.txtThumbnail);
     imageView=(ImageView)itemView.findViewById(R.id.imageView);

    itemView.setOnClickListener(this);
    itemView.setOnLongClickListener(this);
}

public void setItemClickListener(ItemClickListener itemClickListener) {
    this.itemClickListener = itemClickListener;
}

@Override
public void onClick(View v) {

itemClickListener.onClick(v,getAdapterPosition(),false);
}

@Override
public boolean onLongClick(View v) {
    itemClickListener.onClick(v,getAdapterPosition(),true);
    return true;
}

}

公共类FeedAdapter扩展了RecyclerView.Adapter {

private RSSObject rssObject;
private Context mContext;
private LayoutInflater inflater;

public FeedAdapter(RSSObject rssObject, Context mContext) {
    this.rssObject = rssObject;
    this.mContext = mContext;
    inflater =LayoutInflater.from(mContext);
}

@Override
public FeedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = inflater.inflate(R.layout.row,parent,false);
    return new FeedViewHolder(itemView);
}

@Override
public void onBindViewHolder(FeedViewHolder holder, int position) {
    Picasso.get().load(rssObject.getItems().get(position).getThumbnail()).into(R.id.imageView);
    holder.txtTitle.setText(rssObject.getItems().get(position).getTitle());
    holder.txtPubDate.setText(rssObject.getItems().get(position).getPubDate());
    holder.txtAuthor.setText(rssObject.getItems().get(position).getAuthor());
    holder.txtContent.setText(rssObject.getItems().get(position).getContent());

}

@Override
public int getItemCount() {
    return rssObject.items.size();
}

}

1 个答案:

答案 0 :(得分:1)

试试这个:

ImageView imageView = (ImageView)findViewById(R.id.imageView);
Picasso.get().load(your picture).getThumbnail().into(imageView);