cc_美团 买单界面实现

wKiom1WnPBzDFBkgAAFdC9j--Mw080.jpg


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, "商品数量不能为0");

// Toast.makeText(this, "商品数量不能为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;

}

}


你可能感兴趣的:(cc_美团买单界面实现)