• STD二手图书交流平台团队博客-商品属性与操作


    更新完善商品属性 使得商品信息更加全面 形象更加立体

    便于买家进行判断和分析

    实现对商品的操作 加入购物车以及购买支付的功能

    遇到问题:商品支付不能跳转 并未得到权限

    商品细节

    package com.example.secondhand;

    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;

    import androidx.appcompat.app.AppCompatActivity;


    import static com.example.secondhand.UiUtils.getContext;


    //商品细节显示

    public class DetailActivity extends AppCompatActivity {
    ImageView ivGoodsPic;
    TextView tvGoodsName;
    TextView tvGoodsPrice;
    TextView tvGoodsCategory;
    TextView tvGoodsPhone;
    TextView tvGoodsTime;
    Button btnAddPurchase;
    Button btnAddBuycar;
    TextView tvLiuyan;
    String id;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    ivGoodsPic = findViewById(R.id.ivGoodsPic);
    tvGoodsName = findViewById(R.id.tvGoodsName);
    tvGoodsPrice = findViewById(R.id.tvGoodsPrice);
    tvGoodsCategory = findViewById(R.id.tvGoodsCategory);
    tvGoodsPhone = findViewById(R.id.tvGoodsPhone);
    tvGoodsTime = findViewById(R.id.tvGoodsTime);
    btnAddBuycar = findViewById(R.id.btnAddBuycar);
    btnAddPurchase = findViewById(R.id.btnAddPurchase);
    tvLiuyan = findViewById(R.id.tvLiuyan);
    Bundle b = getIntent().getExtras();
    if (b != null) {
    Bitmap bitmap = b.getParcelable("bitmap");
    ivGoodsPic.setImageBitmap(bitmap);
    tvGoodsName.setText("商品名称:"+b.getString("商品名称:"));
    tvGoodsPrice.setText("商品价格:"+b.getString("商品价格:"));
    tvGoodsCategory.setText("商品分类:"+b.getString("商品分类:")+ "¥");
    tvGoodsPhone.setText("联系电话:"+b.getString("联系电话:"));
    tvGoodsTime.setText("发布时间:"+b.getString("发布时间:"));
    btnAddBuycar.setOnClickListener(listener1);
    btnAddPurchase.setOnClickListener(listener2);
    tvLiuyan.setOnClickListener(listener3);
    id=b.getString("goodsId");
    }
    }
    private View.OnClickListener listener3= new View.OnClickListener(){
    @Override
    public void onClick(View v) {
    Bundle b = getIntent().getExtras();
    Intent intent = new Intent(getContext(), CommentActivity.class);
    intent.putExtras(b);
    startActivity(intent);
    }
    };

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

    private void showDropOutDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("提示");
    builder.setMessage("请确认是否支付?");
    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
    UiUtils.toast("支付成功");
    }
    });
    builder.setNegativeButton("取消",new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
    dialog.dismiss();
    }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
    }

    private View.OnClickListener listener1 = new View.OnClickListener(){
    @Override
    public void onClick(View v) {
    //UiUtils.toast("已加入购物车");
    String goodsId1 = id;
    System.out.println("goodsId : " + goodsId1);
    int raw1 = ProductDao.getInstance().updateGoodsAddBuyCar(goodsId1);
    if (raw1 > 0){
    UiUtils.toast("已加入购物车");
    }else {
    UiUtils.toast("加入失败");
    }
    }
    };
    }

     

  • 相关阅读:
    SVN自动更新测试服务器工作副本(C#写winform程序实现)
    两台服务器上SQL Server数据库数据互操作示例
    ASP.NET根据URL生成网页缩略图示例程序(C#语言)
    Flutter Widget API
    BPM、BPMN、BPMN2.0概念介绍
    H5多图上传调研
    lIUNX如何加载U盘,光盘
    如何解决exchange2003被中继的问题?(网上转载)
    window无法安装服务
    如何在WORD里面插入不同的页眉和页脚
  • 原文地址:https://www.cnblogs.com/jz-no-bug/p/14760270.html
Copyright © 2020-2023  润新知