• STD二手图书交流平台团队博客-界面构建


    更新完善”我的“界面

    功能包括购物车 购买记录 我的发布 修改密码 与退出登录

    写购物车时在商品界面添加购物车后并不能在购物车内正常显示

    商品数量不可以在购物车界面进行修改

    class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    // View view = View.inflate(parent.getContext(), R.layout.adapter_recycler_home, null);
    View view = View.inflate(parent.getContext(), R.layout.item_favour, null);
    MyViewHolder myViewHolder = new MyViewHolder(view);
    return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder2, int position) {
    GoodsBean goodsBean = allByUsername.get(position);
    MyViewHolder holder = (MyViewHolder) holder2;
    String goodsPath = goodsBean.getGoodsPath();
    System.out.println("goodsPath :" + goodsPath);
    Bitmap bitmap = BitmapFactory.decodeFile(goodsPath);
    holder.ivGoodsPic.setBackground(new BitmapDrawable(bitmap));
    holder.tvGoodsName.setText("商品名称:" + goodsBean.getGoodsName());
    holder.tvGoodsPrice.setText("商品价格:" + "¥" +goodsBean.getGoodsPrice());
    holder.tvGoodsCategory.setText("商品分类:" + goodsBean.getGoodsCategory());
    holder.tvGoodsPhone.setText("联系电话:" + goodsBean.getGoodsPhone());
    holder.tvGoodsTime.setText("发布时间:" + goodsBean.getGoodsTime() +" ");
    holder.btnAddPurchase.setTag(position);
    holder.btnFavourCancel.setTag(position);
    if(flag==1 || flag==2){
    if(flag==1) {
    holder.btnAddPurchase.setVisibility(View.GONE);
    holder.btnFavourCancel.setVisibility(View.GONE);
    }
    if(flag==2){
    String id = goodsBean.get_id();
    holder.btnAddPurchase.setTag(id);
    holder.btnFavourCancel.setVisibility(View.GONE);
    holder.btnAddPurchase.setOnClickListener(listener1);
    }
    }else{
    String id = goodsBean.get_id();
    holder.btnFavourCancel.setTag(id);
    holder.btnAddPurchase.setVisibility(View.GONE);
    holder.btnFavourCancel.setOnClickListener(listener);
    }
    }

    @Override
    public int getItemCount() {
    return allByUsername == null ? 0 : allByUsername.size();
    }
    }

    private View.OnClickListener listener1= new View.OnClickListener(){
    @Override
    public void onClick(View v) {
    String goodsId = (String) v.getTag();
    System.out.println("goodsId : " + goodsId);
    int raw = ProductDao.getInstance().updateGoodsBuyed(goodsId);
    if (raw > 0){
    UiUtils.toast("购买成功");
    }else {
    UiUtils.toast("购买失败");
    }
    }
    };

    private View.OnClickListener listener = new View.OnClickListener(){
    @Override
    public void onClick(View v) {
    String goodsId = (String) v.getTag();
    System.out.println("goodsId : " + goodsId);
    int raw = ProductDao.getInstance().updateGoodsBuyedDelete(goodsId);
    if (raw == 0){
    UiUtils.toast("删除成功");
    allByUsername = ProductDao.getInstance().findAllGoodsBeanByUsername();
    releaseRecyclerView.setAdapter(new MyAdapter());
    }else {
    UiUtils.toast("删除失败");
    }
    }
    };


    static class MyViewHolder extends RecyclerView.ViewHolder {
    private ImageView ivGoodsPic;
    private TextView tvGoodsName;
    private TextView tvGoodsPrice;
    private TextView tvGoodsCategory;
    private TextView tvGoodsPhone;
    private TextView tvGoodsTime;
    private Button btnAddPurchase;
    private Button btnFavourCancel;


    public MyViewHolder(@NonNull View itemView) {
    super(itemView);
    ivGoodsPic = itemView.findViewById(R.id.ivGoodsPic);
    tvGoodsName = itemView.findViewById(R.id.tvGoodsName);
    tvGoodsPrice = itemView.findViewById(R.id.tvGoodsPrice);
    tvGoodsCategory = itemView.findViewById(R.id.tvGoodsCategory);
    tvGoodsPhone = itemView.findViewById(R.id.tvGoodsPhone);
    tvGoodsTime = itemView.findViewById(R.id.tvGoodsTime);
    btnFavourCancel = itemView.findViewById(R.id.tv_favour_cancel);
    btnAddPurchase = itemView.findViewById(R.id.btnAddPurchase);
    }
    }

    }

     

  • 相关阅读:
    [HNOI2006]最短母串问题 AC自动机
    【BZOJ】【2946】【POI2000】公共串
    【BZOJ】【1717】【USACO 2006 Dec】Milk Patterns产奶的模式
    【BZOJ】【2084】【POI2010】Antisymmetry
    【BZOJ】【3790】神奇项链
    【BZOJ】【2565】最长双回文串
    【HDOJ】【3068】最长回文
    【BZOJ】【1031】【JSOI2007】字符加密Cipher
    【BZOJ】【3172】【TJOI2013】单词
    【BZOJ】【2938】【POI2000】病毒
  • 原文地址:https://www.cnblogs.com/Yforever/p/14912903.html
Copyright © 2020-2023  润新知