你的位置:首页 > 操作系统

[操作系统]硅谷商城4


1_购物车页面和标题栏的设置

govaffair_pager.

<?

  

2_设置适配器

public class GovaffairPagerAdapter extends RecyclerView.Adapter<GovaffairPagerAdapter.ViewHolder> {  private final Context context;  private final List<ShopingCart> datas;  public GovaffairPagerAdapter(Context context, List<ShopingCart> datas) {    this.context = context;    this.datas = datas;  }  @Override  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {    View view = View.inflate(context, R.layout.item_govaffairpager, null);    return new ViewHolder(view);  }  @Override  public void onBindViewHolder(ViewHolder holder, int position) {    ShoppingCart wares = datas.get(position);    //加载图片    Glide.with(context).load(wares.getImgUrl()).        placeholder(R.drawable.news_pic_default).        error(R.drawable.news_pic_default)        .diskCacheStrategy(DiskCacheStrategy.ALL)        .into(holder.iv_icon);    holder.checkbox.setChecked(cart.isChecked());    holder.tv_name.setText(wares.getName());    holder.tv_price.setText("¥ "+wares.getPrice());    holder.numberAddSubView.setValue(wares.getCount());  }  @Override  public int getItemCount() {    return datas.size();  }  class ViewHolder extends RecyclerView.ViewHolder {    private CheckBox checkbox;    private ImageView iv_icon;    private TextView tv_name;    private TextView tv_price;    private NumberAddSubView numberAddSubView;    public ViewHolder(View itemView) {      super(itemView);      checkbox = (CheckBox) itemView.findViewById(R.id.checkbox);      iv_icon = (ImageView) itemView.findViewById(R.id.iv_icon);      tv_name = (TextView) itemView.findViewById(R.id.tv_name);      tv_price = (TextView) itemView.findViewById(R.id.tv_price);      numberAddSubView = (NumberAddSubView) itemView.findViewById(R.id.numberAddSubView);    }  }}