gpt4 book ai didi

java - onBindViewHolder 无法识别 View 持有者小部件

转载 作者:行者123 更新时间:2023-12-02 11:01:56 25 4
gpt4 key购买 nike

我正在创建一个需要适配器类中的水平回收器 View 的项目,我对 ViewHolder 有问题,它是我的代码:

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{


private ArrayList<String> mNames = new ArrayList<>();
private ArrayList<String> imageUrls = new ArrayList<>();
private Context mContext;

public RecyclerViewAdapter(Context mContext, ArrayList<String> mNames, ArrayList<String> imageUrls) {
this.mNames = mNames;
this.imageUrls = imageUrls;
this.mContext = mContext;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_listitem,viewGroup,false);

return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
Glide.with(mContext)
.asBitmap()
.load(imageUrls.get(i))
.into(viewHolder.image);
}

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

public class ViewHolder extends RecyclerView.ViewHolder{
ImageView image;
TextView name;

public ViewHolder(@NonNull View itemView) {
super(itemView);
image = itemView.findViewById(R.id.iv_overlay);
name = itemView.findViewById(R.id.name);
}
}

}

我的问题是 .into(viewHolder.image) 返回错误:错误:(47, 33) 错误:找不到符号变量图像

我该怎么办?

最佳答案

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {


private ArrayList<String> mNames = new ArrayList<>();
private ArrayList<String> imageUrls = new ArrayList<>();
private Context mContext;

public RecyclerViewAdapter(Context mContext, ArrayList<String> mNames, ArrayList<String> imageUrls) {
this.mNames = mNames;
this.imageUrls = imageUrls;
this.mContext = mContext;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_listitem, viewGroup, false);

return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
Glide.with(mContext)
.asBitmap()
.load(imageUrls.get(i))
.into(viewHolder.image);
}

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

public class ViewHolder extends RecyclerView.ViewHolder {
ImageView image;
TextView name;

public ViewHolder(@NonNull View itemView) {
super(itemView);
image = itemView.findViewById(R.id.iv_overlay);
name = itemView.findViewById(R.id.name);
}
}
}

关于java - onBindViewHolder 无法识别 View 持有者小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51269278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com