商品细节
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("加入失败");
}
}
};
}