温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

cc_美团 买单界面实现

发布时间:2020-08-11 02:53:12 来源:网络 阅读:461 作者:愚人cc 栏目:移动开发

cc_美团 买单界面实现


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;

}

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI