(方法 Glide.with(android.content.Context) 不适用)
( method Glide.with(android.content.Context) is not applicable)
Glide.with(context).load(user.getImageURL()).into(holder.profile_image);
它不起作用 它说(方法 Glide.with(android.content.Context
)不适用 )
public class UserAdopter extends RecyclerView.Adapter <UserAdopter.ViewHolder> {
private Context context ;
private List<User> users ;
public UserAdopter(Context context ,List<User> users){
this.users = users ;
this.context = context ;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
User user = users.get(position);
holder.username.setText(user.getUsername());
if (user.getImageURL().equals("default")){
holder.profile_image.setImageResource(R.mipmap.ic_launcher);
}else {
Glide.with(context).load(user.getImageURL()).into(holder.profile_image);
}
}
@Override
public int getItemCount() {
return users.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView username ;
public ImageView profile_image ;
public ViewHolder(@NonNull View itemView) {
super(itemView);
username = itemView.findViewById(R.id.username);
profile_image = itemView.findViewById(R.id.profile_image);
}
}
}
enter image description here
错误说明了一切:
检查您的导入列表并确保您的上下文实际上是 android.content.Context
Glide.with(context).load(user.getImageURL()).into(holder.profile_image);
它不起作用 它说(方法 Glide.with(android.content.Context
)不适用 )
public class UserAdopter extends RecyclerView.Adapter <UserAdopter.ViewHolder> {
private Context context ;
private List<User> users ;
public UserAdopter(Context context ,List<User> users){
this.users = users ;
this.context = context ;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
User user = users.get(position);
holder.username.setText(user.getUsername());
if (user.getImageURL().equals("default")){
holder.profile_image.setImageResource(R.mipmap.ic_launcher);
}else {
Glide.with(context).load(user.getImageURL()).into(holder.profile_image);
}
}
@Override
public int getItemCount() {
return users.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView username ;
public ImageView profile_image ;
public ViewHolder(@NonNull View itemView) {
super(itemView);
username = itemView.findViewById(R.id.username);
profile_image = itemView.findViewById(R.id.profile_image);
}
}
}
enter image description here
错误说明了一切:
检查您的导入列表并确保您的上下文实际上是 android.content.Context