微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐