package com.jqyd.newprocess; import java.util.ArrayList; import com.jqyd.app.MyApp; import com.jqyd.manager.R; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class GoodEdit extends Activity implements OnClickListener { private EditText spbh; private EditText spmc; private EditText ggxh; private EditText dw; private EditText ckdj; private EditText sjsj; private EditText sl; private Button add; private Button sure; private MyApp myApp; private int num = 0;//购物车中商品的编号 private Bundle bundle = null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.goodedit); spbh = (EditText) this.findViewById(R.id.spbh); spmc = (EditText) this.findViewById(R.id.spmc); ggxh = (EditText) this.findViewById(R.id.ggxh); dw = (EditText) this.findViewById(R.id.dw); ckdj = (EditText) this.findViewById(R.id.ckdj); sjsj = (EditText) this.findViewById(R.id.sjsj); sl = (EditText) this.findViewById(R.id.sl); add = (Button) this.findViewById(R.id.add); sure = (Button) this.findViewById(R.id.sure); add.setOnClickListener(this); sure.setOnClickListener(this); //指定默认获得焦点 sl.setFocusable(true); sl.setFocusableInTouchMode(true); sl.requestFocus(); myApp = (MyApp) this.getApplication(); Intent intent = this.getIntent(); num = intent.getIntExtra("num", 0); System.out.println("购物车中的商品编号------------"+num); loadData(); } /** * 加载数据 */ public void loadData(){ ArrayList<Bundle> goodList = myApp.getGoodList(); bundle = goodList.get(num); spbh.setText(bundle.getString("spbh")); spmc.setText(bundle.getString("p_name")); ggxh.setText(bundle.getString("p_type")); dw.setText(bundle.getString("p_unit")); ckdj.setText(bundle.getString("p_lsj")); sjsj.setText(bundle.getString("p_lsj")); } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == add){ new AlertDialog.Builder(GoodEdit.this).setTitle("提示").setMessage("继续浏览商品吗?") .setPositiveButton("继续", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //清楚上次记忆的分组编号 //myApp.setGroupNums(""); myApp.setGoodGroupNum(""); //添加至购物车 Bundle newBundle = new Bundle(); newBundle.putString("spbh", spbh.getText().toString()); newBundle.putString("spmc", spmc.getText().toString()); newBundle.putString("ggxh", ggxh.getText().toString()); newBundle.putString("dw", dw.getText().toString()); newBundle.putString("ckdj", ckdj.getText().toString()); newBundle.putString("sjsj", sjsj.getText().toString()); newBundle.putString("sl", sl.getText().toString()); //计算单件商品的金额 double prises = 0.0; if(!sl.getText().toString().equals("") && !sjsj.getText().toString().equals("")){ prises = Double.parseDouble(sl.getText().toString()) * Double.parseDouble(sjsj.getText().toString()); } newBundle.putString("prises", prises+""); //取得原来的值 newBundle.putString("spid", bundle.getString("spid")); //重新添加至购物车,覆盖原来的数据 ArrayList<Bundle> goodList = myApp.getGoodList(); goodList.remove(num); goodList.add(newBundle); myApp.setGoodList(goodList); startActivity(new Intent().setClass(GoodEdit.this, GoodGroupList.class)); finish(); } }).setNegativeButton("查看购物车", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //添加至购物车 Bundle newBundle = new Bundle(); newBundle.putString("spbh", spbh.getText().toString()); newBundle.putString("spmc", spmc.getText().toString()); newBundle.putString("ggxh", ggxh.getText().toString()); newBundle.putString("dw", dw.getText().toString()); newBundle.putString("ckdj", ckdj.getText().toString()); newBundle.putString("sjsj", sjsj.getText().toString()); newBundle.putString("sl", sl.getText().toString()); //计算单件商品的金额 double prises = 0.0; if(!sl.getText().toString().equals("") && !sjsj.getText().toString().equals("")){ prises = Double.parseDouble(sl.getText().toString()) * Double.parseDouble(sjsj.getText().toString()); } newBundle.putString("prises", prises+""); //取得原来的值 newBundle.putString("spid", bundle.getString("spid")); //重新添加至购物车,覆盖原来的数据 ArrayList<Bundle> goodList = myApp.getGoodList(); goodList.remove(num); goodList.add(newBundle); myApp.setGoodList(goodList); startActivity(new Intent().setClass(GoodEdit.this, InfoSure.class)); finish(); } }).show(); }else{ ArrayList<Bundle> goodList = myApp.getGoodList(); goodList.remove(num); startActivity(new Intent().setClass(GoodEdit.this, InfoSure.class)); finish(); } } }