package com.gourmetMeal;
import com.gourmetMeal.database.DataShare;
import android.os.Bundle;
import android.content.Intent;import android.view.KeyEvent;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;/**
* 菜单放大 * * bcu * */public class MenuzoominActivity extends CommonActivity implements OnClickListener { /** * 返回按钮 */ private Button menuzooomin_btn_back = null; /** * 点菜按钮 * */ private Button menuzooomin_btn_order = null; /** * 声明Intent跳转 */ private Intent menuzoom_intent = null; /** * 图片 */ private ImageView menuzooomin_img_zoomin = null; /** * 名称 */ private TextView menuzoomin_txt_name = null; /** * 价格 */ private TextView menuzoomin_txt_value = null; /** * 传递过来的名称 */ private String name; /** * 价格过来的价格 */ private String value;@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_menuzoomin); // 初始化UI infoUI(); }private void infoUI() {
/* * 获取UI控件 */ menuzooomin_btn_back = (Button) findViewById(R.id.menuzooomin_btn_back); menuzooomin_btn_order = (Button) findViewById(R.id.menuzooomin_btn_order); menuzooomin_img_zoomin = (ImageView) findViewById(R.id.menuzooomin_img_zoomin); menuzoomin_txt_name = (TextView) findViewById(R.id.menuzoomin_txt_name); menuzoomin_txt_value = (TextView) findViewById(R.id.menuzoomin_txt_value); menuzoom_intent = new Intent();/*
* 获取传递的参数并设置 */ Intent menu_intent = getIntent(); name = menu_intent.getStringExtra("name"); value = menu_intent.getStringExtra("value"); menuzoomin_txt_name.setText(name); menuzoomin_txt_value.setText(value); menuzooomin_img_zoomin.setImageBitmap(CommonActivity.menu_imgres);/*
* 设置监听事件 */ menuzooomin_btn_back.setOnClickListener(MenuzoominActivity.this); menuzooomin_btn_order.setOnClickListener(MenuzoominActivity.this); }/**
* 点击事件 */ public void onClick(View v) { switch (v.getId()) { case R.id.menuzooomin_btn_back: // 返回按钮 /* * 跳转至主界面 */ menuzoom_intent.setClass(MenuzoominActivity.this, MenuActivity.class); startActivity(menuzoom_intent); this.finish(); break; case R.id.menuzooomin_btn_order: // 点菜按钮 foodname = name; // 获取菜名 theFood = sqlfood(); // 设置theFood类/*
* 判断菜是否已被点,计算数量和总价 */ int index = DataShare.isExistGoods(foodid); if (index != -1) {// 已添加过该商品 DataShare.shopList.get(index).setNum( DataShare.shopList.get(index).getNum() + 1); DataShare.shopList.get(index).setJiage( DataShare.shopList.get(index).getNum() * DataShare.shopList.get(index).getDanjia()); } else {theFood.setNum(1);
theFood.setJiage(fooddanjia);
System.out.println(theFood.getJiage() + "!!!"); DataShare.shopList.add(theFood); } Toast.makeText(this, "您选了" + foodname, Toast.LENGTH_LONG).show(); break; } }/**
* 重写返回键 */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { /* * 跳转至主界面 */ if (keyCode == KeyEvent.KEYCODE_BACK) { menuzoom_intent.setClass(MenuzoominActivity.this, MenuActivity.class); startActivity(menuzoom_intent); this.finish(); } return false; }}xml:
<RelativeLayout xmlns:android=""
xmlns:tools="" android:background="@drawable/menu_background" android:layout_width="match_parent" android:layout_height="match_parent" ><RelativeLayout
android:id="@+id/menuzooomin_relativeLayout_above" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_above="@+id/menuzooomin_relativeLayout_below"><ImageView
android:id="@+id/menuzooomin_img_zoomin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="10dp" android:layout_alignParentBottom="true" android:src="@drawable/gallery4" /> </RelativeLayout> <RelativeLayout android:id="@+id/menu_scr_RelativeLayoutinformation" android:layout_alignLeft="@+id/menuzooomin_img_zoomin" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/menuzoomin_txt_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:text="蓝莓山药" android:background="#FF0000" android:textColor="#FFFF00" android:textStyle="bold" android:textSize="15dp"/> <TextView android:id="@+id/menuzoomin_txt_value" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_marginTop="10dp" android:layout_marginLeft="10dp" android:layout_below="@+id/menuzoomin_txt_name" android:text="10元" android:background="#FF0000" android:textColor="#FFFF00" android:textStyle="bold" android:textSize="15dp"/> </RelativeLayout> <RelativeLayout android:id="@+id/menuzooomin_relativeLayout_below" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_marginBottom="11dp" android:layout_alignParentBottom="true"><Button
android:id="@+id/menuzooomin_btn_order" android:textColor="#FFFFFF" android:background="@layout/button_order" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:text="" /><Button
android:id="@+id/menuzooomin_btn_back" android:textColor="#FFFFFF" android:background="@layout/button_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginTop="10dp" android:layout_toLeftOf="@+id/menuzooomin_btn_order" android:text="" /></RelativeLayout>
</RelativeLayout>