在这里插入代码片
public class ConfirmOrderAdapter extends RecyclerView.Adapter<ConfirmOrderAdapter.ViewHolder> {
private Context context;
private List<HomeshopsBean> homeshopsBeans;//数据源集合
public ConfirmOrderAdapter(Context context, List<HomeshopsBean> homeshopsBeans) {
this.context = context;
this.homeshopsBeans = homeshopsBeans;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(context).inflate(R.layout.confirm_order_item, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
HomeshopsBean homeshopsBean = homeshopsBeans.get(position);
//设置数据
holder.username.setText(homeshopsBean.getUser().getUsername());
holder.bookname.setText(homeshopsBean.getBookname());
holder.appearance.setText(homeshopsBean.getAppearance());
holder.location.setText(homeshopsBean.getLocation());
holder.nowprice.setText("¥"+homeshopsBean.getNowprice());
//使用的是Glide加载(要使用自己的网络请求框架+二次采样)
String[] images = homeshopsBean.getImages().split(",");
Glide.with(context).load(images[0]).into(holder.bookImage);
}
@Override
public int getItemCount() {
return homeshopsBeans.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.username)
TextView username;
@BindView(R.id.bookImage)
ImageView bookImage;
@BindView(R.id.bookname)
TextView bookname;
@BindView(R.id.appearance)
TextView appearance;
@BindView(R.id.location)
TextView location;
@BindView(R.id.nowprice)
TextView nowprice;
public ViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this,itemView);
}
}
}