您好,登錄后才能下訂單哦!
package com.chencheng.meituan.view;
import com.chencheng.db.DBManager;
import com.chencheng.meituan.util.ToastUtil;
import com.chencheng.model.Goodlist;
import com.yuchen.meituan.R;
import com.yuchen.meituan.R.id;
import com.yuchen.meituan.R.layout;
import com.yuchen.meituan.R.menu;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class PayActivity extends Activity implements OnClickListener {
private static final String VALID_NUM = "[0-9]+";
private Goodlist mGoodlist;
private TextView mTvProduct;
private TextView mTvPrice;
private EditText mEditNum;
private TextView mTvValues;
private TextView mTvBottomValues;
private TextView mTvBottomNum;
private ImageView mBtnReduce;
private ImageView mBtnAdd;
private int num = 1;
private String mPrice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pay);
mGoodlist = (Goodlist) getIntent().getSerializableExtra("goods");
initUI();
initData();
}
private void initData() {
mPrice = mGoodlist.getPrice();
mTvProduct.setText(mGoodlist.getProduct());
mTvPrice.setText(mPrice);
mTvValues.setText(mPrice);
mTvBottomValues.setText(mPrice);
}
private void initUI() {
mTvProduct = (TextView) findViewById(R.id.tv_product);
mTvPrice = (TextView) findViewById(R.id.tv_price);
mEditNum = (EditText) findViewById(R.id.edit_num);
mTvValues = (TextView) findViewById(R.id.tv_all_price);
mTvBottomValues = (TextView) findViewById(R.id.tv_bottom_values);
mTvBottomNum = (TextView) findViewById(R.id.tv_num_bottom);
mBtnReduce = (ImageView) findViewById(R.id.img_reduce);
mBtnAdd = (ImageView) findViewById(R.id.img_add);
mBtnReduce.setOnClickListener(this);//減
mBtnAdd.setOnClickListener(this);//加
findViewById(R.id.back_btn).setOnClickListener(this);
findViewById(R.id.tv_login).setOnClickListener(this);//直接登錄
findViewById(R.id.btn_to_pay).setOnClickListener(this);//支付
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.back_btn:
finish();
break;
case R.id.tv_login:
//直接登錄
startActivity(new Intent(this, LoginActivity.class));
break;
case R.id.btn_to_pay:
//支付
ToastUtil.showToast(this, "已支付");
DBManager.insertToDB(mGoodlist , "pay");
// Toast.makeText(this, "已支付", Toast.LENGTH_SHORT).show();
break;
case R.id.img_reduce:
//減
reduceAdd();
break;
case R.id.img_add:
//加
addNum();
break;
default:
break;
}
}
private void reduceAdd() {
num--;
if(num <= 1){
mBtnReduce.setBackgroundResource(R.drawable.btn_minus_a);
}
if(num < 1){
ToastUtil.showToast(this, "商品數(shù)量不能為0");
// Toast.makeText(this, "商品數(shù)量不能為0", Toast.LENGTH_SHORT).show();
mEditNum.setText("" + 1);
num = 1;
return;
}
mEditNum.setText("" + num);
mTvValues.setText("" + num * Integer.valueOf(mPrice));
mTvBottomValues.setText("" + num * Integer.valueOf(mPrice));
mTvBottomNum.setText("" + num);
}
private void addNum() {
num ++;
if(num > 1){
mBtnReduce.setBackgroundResource(R.drawable.btn_minus_b);
}
if(num > 100){
return;
}
mEditNum.setText("" + num);
mTvValues.setText("" + num * Integer.valueOf(mPrice));
mTvBottomValues.setText("" + num * Integer.valueOf(mPrice));
mTvBottomNum.setText("" + num);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pay, menu);
return false;
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。