picasso 中的 get() 不能应用于 (android.content.context)
get() in picasso cannot be applied to (android.content.context)
在观看教程视频后,我在 android studio 上有以下代码。然而,在教程视频中,上传者使用了:
implementation 'com.android.picasso:picasso:2.5.2'
而我不得不使用
implementation 'com.squareup.picasso:picasso:2.71828'
适配器Class
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);
}
}
}
如上所述,Picasso 行给我错误:get() in picasso cannot be applied to (android.content.context)
谢谢!
因为毕加索 2.71828
你不需要在 Picasso.get()
中提供 Context
有关详细信息,请参阅 ChangeLog
Picasso#get()
没有上下文。如果需要使用不同的上下文,可以使用 new Picasso.Builder(mContext).build();
或者,Picasso.get()
就足够了。
毕加索 with(Context)
已重命名为 get()
在观看教程视频后,我在 android studio 上有以下代码。然而,在教程视频中,上传者使用了:
implementation 'com.android.picasso:picasso:2.5.2'
而我不得不使用
implementation 'com.squareup.picasso:picasso:2.71828'
适配器Class
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);
}
}
}
如上所述,Picasso 行给我错误:get() in picasso cannot be applied to (android.content.context)
谢谢!
因为毕加索 2.71828
你不需要在 Picasso.get()
Context
有关详细信息,请参阅 ChangeLog
Picasso#get()
没有上下文。如果需要使用不同的上下文,可以使用 new Picasso.Builder(mContext).build();
或者,Picasso.get()
就足够了。
毕加索 with(Context)
已重命名为 get()