android商品详情

商品信息展示功能

  1 package com.example.secondhand;
  2 
  3 import android.app.AlertDialog;
  4 import android.content.DialogInterface;
  5 import android.content.Intent;
  6 import android.graphics.Bitmap;
  7 import android.os.Bundle;
  8 import android.view.View;
  9 import android.widget.Button;
 10 import android.widget.ImageView;
 11 import android.widget.TextView;
 12 
 13 import androidx.appcompat.app.AppCompatActivity;
 14 
 15 
 16 import static com.example.secondhand.UiUtils.getContext;
 17 
 18 
 19 //商品细节显示
 20 
 21 public class DetailActivity extends AppCompatActivity {
 22 ImageView ivGoodsPic;
 23 TextView tvGoodsName;
 24 TextView tvGoodsPrice;
 25 TextView tvGoodsCategory;
 26 TextView tvGoodsPhone;
 27 TextView tvGoodsTime;
 28 Button btnAddPurchase;
 29 Button btnAddBuycar;
 30 TextView tvLiuyan;
 31 String id;
 32 
 33 
 34 @Override
 35 protected void onCreate(Bundle savedInstanceState) {
 36 super.onCreate(savedInstanceState);
 37 setContentView(R.layout.activity_detail);
 38 ivGoodsPic = findViewById(R.id.ivGoodsPic);
 39 tvGoodsName = findViewById(R.id.tvGoodsName);
 40 tvGoodsPrice = findViewById(R.id.tvGoodsPrice);
 41 tvGoodsCategory = findViewById(R.id.tvGoodsCategory);
 42 tvGoodsPhone = findViewById(R.id.tvGoodsPhone);
 43 tvGoodsTime = findViewById(R.id.tvGoodsTime);
 44 btnAddBuycar = findViewById(R.id.btnAddBuycar);
 45 btnAddPurchase = findViewById(R.id.btnAddPurchase);
 46 tvLiuyan = findViewById(R.id.tvLiuyan);
 47 Bundle b = getIntent().getExtras();
 48 if (b != null) {
 49 Bitmap bitmap = b.getParcelable("bitmap");
 50 ivGoodsPic.setImageBitmap(bitmap);
 51 tvGoodsName.setText("商品名称:"+b.getString("商品名称:"));
 52 tvGoodsPrice.setText("商品价格:"+b.getString("商品价格:"));
 53 tvGoodsCategory.setText("商品分类:"+b.getString("商品分类:")+ "¥");
 54 tvGoodsPhone.setText("联系电话:"+b.getString("联系电话:"));
 55 tvGoodsTime.setText("发布时间:"+b.getString("发布时间:"));
 56 btnAddBuycar.setOnClickListener(listener1);
 57 btnAddPurchase.setOnClickListener(listener2);
 58 tvLiuyan.setOnClickListener(listener3);
 59 id=b.getString("goodsId");
 60 }
 61 }
 62 private View.OnClickListener listener3= new View.OnClickListener(){
 63 @Override
 64 public void onClick(View v) {
 65 Bundle b = getIntent().getExtras();
 66 Intent intent = new Intent(getContext(), CommentActivity.class);
 67 intent.putExtras(b);
 68 startActivity(intent);
 69 }
 70 };
 71 
 72 private View.OnClickListener listener2= new View.OnClickListener(){
 73 @Override
 74 public void onClick(View v) {
 75 String goodsId = id;
 76 int checkId;
 77 System.out.println("goodsId : " + goodsId);
 78 int raw = ProductDao.getInstance().updateGoodsBuyed(goodsId);
 79 if (raw > 0){
 80 showDropOutDialog();
 81 }else {
 82 UiUtils.toast("购买失败!");
 83 }
 84 }
 85 };
 86 
 87 private void showDropOutDialog() {
 88 AlertDialog.Builder builder = new AlertDialog.Builder(this);
 89 builder.setTitle("提示");
 90 builder.setMessage("请确认是否支付?");
 91 builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
 92 @Override
 93 public void onClick(DialogInterface dialog, int which) {
 94 UiUtils.toast("支付成功");
 95 }
 96 });
 97 builder.setNegativeButton("取消",new DialogInterface.OnClickListener() {
 98 @Override
 99 public void onClick(DialogInterface dialog, int which) {
100 dialog.dismiss();
101 }
102 });
103 AlertDialog alertDialog = builder.create();
104 alertDialog.show();
105 }
106 
107 private View.OnClickListener listener1 = new View.OnClickListener(){
108 @Override
109 public void onClick(View v) {
110 //UiUtils.toast("已加入购物车");
111 String goodsId1 = id;
112 System.out.println("goodsId : " + goodsId1);
113 int raw1 = ProductDao.getInstance().updateGoodsAddBuyCar(goodsId1);
114 if (raw1 > 0){
115 UiUtils.toast("已加入购物车");
116 }else {
117 UiUtils.toast("加入失败");
118 }
119 }
120 };
121 }

原文地址:https://www.cnblogs.com/znjy/p/14908918.html