DetailCheckoutActivity
package cn.thewee.gourmetmeal.staff; import java.util.HashMap; import android.app.ProgressDialog; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import cn.thewee.gourmetmeal.staff.adapter.CheckoutDetailAdapter; import cn.thewee.gourmetmeal.staff.logic.OrderLogic; public class DetailCheckoutActivity extends BaseActivity { private static final String TAG = "DetailCheckoutActivity"; String username; String order_id; TextView tv_orderId4checkDetail; TextView tv_totalPrice4checkDetail; EditText tv_memberName; ListView list_dishes4checkDetail; Button btn_back2checkout; Button btn_checkoutOrder; CheckoutDetailAdapter adapter; Handler my_handler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub if (p_dialog.isShowing()) { p_dialog.dismiss(); } switch (msg.what) { case WHAT_LOADING_COMPLETED:// 数据读取结束 // System.out.println("fsdfsfsfs"+adapter.getDishList()); // 刷新列表 adapter.notifyDataSetChanged(); // 添入总价 setTextView( tv_totalPrice4checkDetail, new String[] { getString(R.string.total_price), String.valueOf(OrderLogic.getOrderSum(adapter .getDishList())) }); list_dishes4checkDetail.setAdapter(adapter); break; case WHAT_SUBMIT_COMPLETE:// 提交完成 Log.i("aaa", msg.getData().getInt("msg") + " " + msg.getData().getInt("rt")); if (msg.getData().getInt("code") == 200) { Toast.makeText(getApplicationContext(), msg.getData().getString("msg"), Toast.LENGTH_SHORT) .show(); DetailCheckoutActivity.this.finish(); } else { Toast.makeText(getApplicationContext(), msg.getData().getString("msg"), Toast.LENGTH_SHORT) .show(); } break; case WHAT_SUBMIT_FAILED:// 提交失败,无返回值 Toast.makeText(getApplicationContext(), getString(R.string.net_timeout), Toast.LENGTH_SHORT) .show(); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 初始化进度对话框 p_dialog.setMessage(getString(R.string.is_loading)); p_dialog.show(); // 创建adapter实例 adapter = new CheckoutDetailAdapter(this); // 启动新线程获取订单明细列表 adapter.setDishList(OrderLogic.getOrderItems( DetailCheckoutActivity.this, order_id, username)); System.out.println("WHAT_LOADING_COMPLETED"); // 给handler发送消息 my_handler.sendEmptyMessage(WHAT_LOADING_COMPLETED); } /** * 初始化控件 */ @Override protected void initViews() { this.setContentView(R.layout.detail_checkout); tv_orderId4checkDetail = (TextView) findViewById(R.id.tv_orderId4checkDetail); tv_totalPrice4checkDetail = (TextView) findViewById(R.id.tv_totalPrice4checkDetail); tv_memberName = (EditText) findViewById(R.id.tv_memberName); list_dishes4checkDetail = (ListView) findViewById(R.id.list_dishes4checkDetail); btn_back2checkout = (Button) findViewById(R.id.btn_back2checkout); btn_checkoutOrder = (Button) findViewById(R.id.btn_checkoutOrder); // 给ListView配置适配器 list_dishes4checkDetail.setAdapter(adapter); // 添入流水号 setTextView(tv_orderId4checkDetail, new String[] { getString(R.string.order_id), order_id }); // 添入总价 // setTextView(tv_totalPrice4checkDetail, // new String[]{ // getString(R.string.total_price), // String.valueOf(OrderLogic.getOrderSum(adapter.getDishList())) // } // ); // 返回按钮配置监听器 btn_back2checkout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DetailCheckoutActivity.this.finish(); } }); // btn_checkoutOrder.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { submitCheckout(); } }); } /** * 提交订单信息 */ private void submitCheckout() { // 显示进度条对话框 if (!p_dialog.isShowing()) { p_dialog.show(); } new Thread() { @Override public void run() { // 提交结单信息,获取返回信息 HashMap<String, Object> result = OrderLogic.checkOrder( order_id, username, tv_memberName.getText().toString(), OrderLogic.getOrderSum(adapter.getDishList())); if (result != null) { Message msg = my_handler.obtainMessage(); msg.what = WHAT_SUBMIT_COMPLETE; Bundle data = new Bundle(); data.putInt("code", Integer.valueOf((String) result.get("rt"))); data.putString("msg", (String) result.get("rtmsg")); msg.setData(data); my_handler.sendMessage(msg); } else { my_handler.sendEmptyMessage(WHAT_SUBMIT_FAILED); } } }.start(); } @Override protected void getExtras() { // 获取传值 username = getIntent().getStringExtra("username"); order_id = getIntent().getStringExtra("order_id"); } }
detail_checkout
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/menu_background" android:orientation="vertical" android:paddingLeft="25dp" android:paddingRight="25dp" android:paddingTop="25dp" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:id="@+id/tv_orderId4checkDetail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/order_id" android:textColor="#000000" /> <TextView android:id="@+id/tv_totalPrice4checkDetail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:text="@string/total_price" android:textColor="#000000" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="right" android:text="@string/member_name" android:textColor="#000000" /> <EditText android:id="@+id/tv_memberName" android:layout_width="140dp" android:layout_height="wrap_content" android:background="@drawable/input_bg" android:singleLine="true" android:textSize="10sp" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/title_bg" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="@string/index" android:textColor="#000000" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="3" android:gravity="center" android:text="@string/dish_name" android:textColor="#000000" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="@string/unit_price" android:textColor="#000000" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="@string/count" android:textColor="#000000" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="@string/price" android:textColor="#000000" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="@string/dishclass" android:textColor="#000000" /> </LinearLayout> <ListView android:id="@+id/list_dishes4checkDetail" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/border3" android:cacheColorHint="#00000000" android:fadingEdge="none" android:listSelector="#12edf8" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:layout_marginTop="10dp" android:gravity="right|center_vertical" > <Button android:id="@+id/btn_back2checkout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="5dp" android:background="@drawable/btn_back" /> <Button android:id="@+id/btn_checkoutOrder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/btn_ok" /> </LinearLayout> </LinearLayout>