在观看了教学视频之后,我在android studio上有了以下代码。但是,在教学视频中,上传者使用了:
implementation 'com.android.picasso:picasso:2.5.2'
我不得不使用
implementation 'com.squareup.picasso:picasso:2.71828'
适配器类
public class adapter extends RecyclerView.Adapter<adapter.viewHolder> {
private Context mContext;
private ArrayList<ItemActivity> mExampleList;
public adapter(Context context, ArrayList<ItemActivity> exampleList)
{
mContext = context;
mExampleList = exampleList;
}
@NonNull
@Override
public viewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
View v =
LayoutInflater.from(mContext).inflate(R.layout.itemlayout, parent, false);
return new viewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull viewHolder holder, int position)
{
ItemActivity currentItem = mExampleList.get(position);
String imageUrl = currentItem.getImageUrl();
String creatorName = currentItem.getCreator();
int likeCount = currentItem.getLikeCount();
holder.mTextViewCreator.setText(creatorName);
holder.mTextViewLikes.setText("Likes: "+likeCount);
Picasso.get(mContext).load(imageUrl).
fit().centerInside.into(holder.mImageView);//get() in picasso
cannot be applied to
(android.content.context)
}
@Override
public int getItemCount() {
return mExampleList.size();
}
public class viewHolder extends RecyclerView.ViewHolder
{
public ImageView mImageView;
public TextView mTextViewCreator;
public TextView mTextViewLikes;
public viewHolder(@NonNull View itemView) {
super(itemView);
mTextViewCreator = itemView.findViewById(R.id.image_view);
mImageView = itemView.findViewById(R.id.text_view_creator);
mTextViewLikes = itemView.findViewById(R.id.text_view_likes);
}
}
}
如上所述,毕加索行给我一个错误:毕加索中的get()无法应用于(android.content.context)
谢谢!
答案 0 :(得分:1)
自毕加索2.71828
起,您无需在Context
中提供Picasso.get()
有关更多信息,请参见ChangeLog
答案 1 :(得分:1)
Picasso#get()
没有上下文。如果需要使用其他上下文,则可以使用new Picasso.Builder(mContext).build();
或者,Picasso.get()
就足够了。
答案 2 :(得分:1)
毕加索with(Context)
已重命名为get()