android点餐系统 部分功能源代码

上传者: fyl_0 | 上传时间: 2022-05-29 18:50:07 | 文件大小: 2.84MB | 文件类型: ZIP
package com.yd.activity; import com.yd.adapter.ImageAdapter; import com.yd.data.IndentData; import com.yd.data.RefreshData; import com.yd.myindent.R; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.AdapterView; import android.widget.Button; import android.widget.GridView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; public class Indent extends Activity { private Button myboard = null ; // 定义按钮 private TextView mych = null ; private int witch = 0; IndentData data; private GridView gridview =null; private int[] imgids = new int[] {R.drawable.img_01,R.drawable.img_02, R.drawable.img_03, R.drawable.img_04, R.drawable.img_05, R.drawable.img_06, R.drawable.img_07, R.drawable.img_08, R.drawable.img_09,R.drawable.img_10,R.drawable.img_11, R.drawable.img_12, R.drawable.img_13, R.drawable.img_14, R.drawable.img_15}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.main); this.gridview=(GridView)super.findViewById(R.id.GridView); this.gridview.setAdapter(new ImageAdapter(this, this.imgids)); this.gridview.setOnItemClickListener(new OnItemClickListenerImpl()); this.myboard = (Button) super.findViewById(R.id.myboard) ; // 取得按钮 this.mych = (TextView) super.findViewById(R.id.mych) ; // 取得文本 this.myboard.setOnClickListener(new OnClickListenerImpl()) ; // 设置事件类 } //视图布局 private class OnItemClickListenerImpl implements OnItemClickListener { public void onItemClick(AdapterView<?> parent, View view, int img, long id) { Indent.this.witch=img; ImageView showImg = new ImageView(Indent.this); showImg.setScaleType(ImageView.ScaleType.CENTER); // 图片居中显示 showImg.setLayoutParams(new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); showImg.setImageResource(Indent.this.imgids[img]); // 设置显示图片 Dialog dialog = new AlertDialog.Builder(Indent.this) .setIcon(R.drawable.img_m).setTitle("订购") .setView(showImg).setNegativeButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { /* Log.v(" R.drawable.img_01 ", "-------------------" + R.drawable.img_01); Log.v(" R.drawable.img_01 ", "-------------------" + R.drawable.img_02); Log.v(" R.drawable.img_01 ", "-------------------" + R.drawable.img_03); Log.v(" R.drawable.img_01 ", "-------------------" + R.drawable.img_04); */ Log.v(" witch ","-----------"+Indent.this.imgids[Indent.this.witch]); if(IndentData.num!=null) { switch(Indent.this.imgids[Indent.this.witch]){ // 判断操作的菜单ID case R.drawable.img_01: IndentData.bill=IndentData.bill+IndentData.PRICE_01; IndentData.fool_01=IndentData.fool_01+1; Log.v("bill", "-----------"+IndentData.bill); Log.v("bill", "-----------"+IndentData.fool_01); break ; case R.drawable.img_02: IndentData.bill=IndentData.bill+IndentData.PRICE_02; IndentData.fool_02=IndentData.fool_02+1; Log.v("Indent.this.data.getBill()", "-----------"+IndentData.bill); Log.v("Indent.this.data.getFool_02()", "-----------"+IndentData.fool_02); break ; case R.drawable.img_03: IndentData.fool_03=IndentData.fool_03+1; IndentData.bill=IndentData.bill+IndentData.PRICE_03; Log.v("Indent.this.data.getBill()", "-----------"+IndentData.bill); Log.v("Indent.this.data.getFool_03()", "-----------"+IndentData.fool_03); break ; case R.drawable.img_04: IndentData.fool_04=IndentData.fool_04+1; IndentData.bill=IndentData.bill+IndentData.PRICE_04; Log.v("Indent.this.data.getBill()", "-----------"+IndentData.bill); Log.v("Indent.this.data.getFool_04()", "-----------"+IndentData.fool_04); break ; case R.drawable.img_05: IndentData.fool_05=IndentData.fool_05+1; IndentData.bill=IndentData.bill+IndentData.PRICE_05; Log.v("Indent.this.data.getBill()", "-----------"+IndentData.bill); Log.v("Indent.this.data.getFool_05()", "-----------"+IndentData.fool_05); break ; case R.drawable.img_06: IndentData.fool_06=IndentData.fool_06+1; IndentData.bill=IndentData.bill+IndentData.PRICE_06; Log.v("6", "打印"); break ; case R.drawable.img_07: IndentData.fool_07=IndentData.fool_07+1; IndentData.bill=IndentData.bill+IndentData.PRICE_07; Log.v("7", "打印"); break ; case R.drawable.img_08: IndentData.fool_08=IndentData.fool_08+1; IndentData.bill=IndentData.bill+IndentData.PRICE_08; Log.v("8", "打印"); break ; case R.drawable.img_09: IndentData.fool_09=IndentData.fool_09+1; IndentData.bill=IndentData.bill+IndentData.PRICE_09; Log.v("9", "打印"); break ; case R.drawable.img_10: IndentData.fool_10=IndentData.fool_10+1; IndentData.bill=IndentData.bill+IndentData.PRICE_10; Log.v("10", "打印"); break ; case R.drawable.img_11: IndentData.fool_11=IndentData.fool_11+1; IndentData.bill=IndentData.bill+IndentData.PRICE_11; Log.v("10", "打印"); break ; case R.drawable.img_12: IndentData.fool_12=IndentData.fool_12+1; IndentData.bill=IndentData.bill+IndentData.PRICE_12; Log.v("10", "打印"); break ; case R.drawable.img_13: IndentData.fool_13=IndentData.fool_13+1; IndentData.bill=IndentData.bill+IndentData.PRICE_13; Log.v("10", "打印"); break ; case R.drawable.img_14: IndentData.fool_14=IndentData.fool_14+1; IndentData.bill=IndentData.bill+IndentData.PRICE_14; Log.v("10", "打印"); break ; case R.drawable.img_15: IndentData.fool_15=IndentData.fool_15+1; IndentData.bill=IndentData.bill+IndentData.PRICE_15; Log.v("10", "打印"); break ; } } /*try{ if(Indent.this.imgids[Indent.this.witch] == R.drawable.img_01){ Log.v("01", "---------"+R.drawable.img_01); } else { Log.v("02", "---------"+R.drawable.img_02); } }catch(Exception e){ Log.v("02","++++++++++++"+e); }*/ } }).create(); dialog.show() ; } } //菜单 @Override public boolean onCreateOptionsMenu(Menu menu) { SubMenu selMenu = menu.addSubMenu("查看") ; SubMenu insMenu = menu.addSubMenu("更正") ; super.getMenuInflater().inflate(R.menu.selmenu, selMenu) ; super.getMenuInflater().inflate(R.menu.insmenu, insMenu) ; return true ; } public boolean onOptionsItemSelected(MenuItem item) { Log.v("item.getItemId()", "------------------------"+item.getItemId()); switch(item.getItemId()) { // 判断操作的菜单ID case R.id.item01: Log.v("R.id.item01", "------------------------"+R.id.item01); if(IndentData.num!=null){ Toast.makeText(this, "预览", Toast.LENGTH_LONG).show() ; Intent intent = new Intent(); intent.setClass(Indent.this, LookActivity.class); this.startActivityForResult(intent, 1); }else{ Toast.makeText(this, "座位已经满了欢迎下次光临", Toast.LENGTH_LONG).show() ; } break ; case R.id.item02: Toast.makeText(this, "查看订单情况", Toast.LENGTH_LONG).show() ; Log.v("R.id.item02", "------------------------"+R.id.item02); break ; case R.id.item03: Toast.makeText(this, "取消当前订单", Toast.LENGTH_LONG).show() ; new RefreshData(); Log.v("R.id.item03", "------------------------"+R.id.item03); break ; case R.id.item04: Toast.makeText(this, "保存", Toast.LENGTH_LONG).show() ; Log.v("R.id.item04", "------------------------"+R.id.item04); break ; case R.id.item05: Toast.makeText(this, "退出程序", Toast.LENGTH_LONG).show() ; Log.v("R.id.item05", "------------------------"+R.id.item05); Indent.this.finish() ; break ; } return false; } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (resultCode) { // 判断操作类型 case RESULT_OK: // 成功操作 Log.v("resultCodeRESULT_OK", "------------------------"+RESULT_OK); break; case RESULT_CANCELED: // 取消操作 new RefreshData(); Indent.this.finish() ; Log.v("resultRESULT_CANCELED", "------------------------"+RESULT_CANCELED); break ; default: break; } } //下拉框 private class OnClickListenerImpl implements OnClickListener { public void onClick(View view) { Dialog dialog = new AlertDialog.Builder(Indent.this) .setIcon(R.drawable.img_m) .setTitle("请选择座位") .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).setItems(R.array.board_labels, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { IndentData.num=Indent.this.getResources().getStringArray(R.array.board_labels)[which]; Indent.this.mych.setText("您选择的座位是:"+ IndentData.num); } }).create() ; dialog.show() ; } } }

文件下载

评论信息

  • u012093726 :
    刚开始学,还没有细看
    2016-02-22
  • wwezjc :
    这个代码 挺有用的 研究挺久的
    2015-11-21
  • u013628196 :
    这个代码 挺有用的 研究挺久的
    2015-01-21
  • legend0066 :
    有一定的参考价值
    2014-05-14
  • sys5923812 :
    可以参考一下,谢谢提供
    2014-02-10

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明