MessageActivity

MessageActivity:

package com.gourmetMeal;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.KeyEvent;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class MessageActivity extends CommonActivity implements
  android.view.View.OnClickListener {
 /**
  * 账号TextView
  */
 private TextView txt_user;
 /**
  * 等级TextView
  */
 private TextView txt_lv;
 /**
  * 流水号TextView
  */
 private TextView txt_liushui;
 /**
  * 桌号TextView
  */
 private TextView txt_table;
 /**
  * 显示信息ListView
  */
 private ListView listview;
 /**
  * 信息Button
  */
 private Button message_btn_back;
 /**
  * 消息传递
  */
 private Intent intent = new Intent();

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_message);
        intent=getIntent();
        String s=intent.getStringExtra("id");
        cursor= database.rawQuery("select liushuizhanghao from liushuibiao where _id="+s+"",null);
  cursor.moveToFirst();
  String liushuiId=cursor.getString(0);
  System.out.println("!!!!"+liushuiId);
        txt_user = (TextView) findViewById(R.id.txt_message_user);
  txt_lv = (TextView) findViewById(R.id.txt_message_lv);
  txt_liushui = (TextView) findViewById(R.id.txt_message_liushui);
  txt_table = (TextView) findViewById(R.id.txt_message_table);
  txt_user.setText(username);
  txt_lv.setText("1");
  listview = (ListView) findViewById(R.id.listView_message);
  message_btn_back = (Button) findViewById(R.id.message_btn_back);
  message_btn_back.setOnClickListener(MessageActivity.this);

  /**
   * 显示流水号的具体信息
   */
   txt_liushui.setText(liushuiId);
   cursor=database.rawQuery("SELECT tablenum FROM xiadan WHERE liushuihao=?", new String[]{liushuiId});
   cursor.moveToFirst();
   txt_table.setText(cursor.getString(0));

   cursor = database
     .rawQuery(
       "SELECT _id,xuhao,caiming,danjia,shuliang,jiage FROM xiadan WHERE liushuihao=?",
       new String[] { liushuiId });
   if (cursor != null) {
    SimpleCursorAdapter sca = new SimpleCursorAdapter(
      MessageActivity.this, R.layout.style_message_listview,
      cursor, new String[] { "xuhao", "caiming", "danjia",
        "shuliang", "jiage" }, new int[] {
        R.id.txt_messagelist_no,
        R.id.txt_messagelist_name,
        R.id.txt_messagelist_price,
        R.id.txt_messagelist_num,
        R.id.txt_messagelist_prices });
    listview.setAdapter(sca);
   }
  }


 /**
  * 按钮点击事件
  */
 public void onClick(View v) {
  switch (v.getId()) {
  case R.id.message_btn_back:
   intent.setClass(MessageActivity.this, MainActivity.class);
   startActivity(intent);
   this.finish();
   break;
  }
 }

 /**
  * 重写键盘按键按下是触发该方法
  */
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_BACK) {
   intent.setClass(MessageActivity.this, MainActivity.class);
   startActivity(intent);
   this.finish();
  }
  return false;
 }
}

ChooseMessageActivity:

package com.gourmetMeal;

 

 

import com.gourmetMeal.database.MyAdapter_FootSoft;
import com.gourmetMeal.database.MyDataBase;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class ChooseMessageActivity extends CommonActivity {
 private ListView listView1;
 private Intent intent;
 private SQLiteDatabase database;
 private Cursor cursor = null;
 private String biaoming;
 public void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_choosemessage);
  
  intent = getIntent();
  //biaoming = intent.getStringExtra("biaoming");
 }
 protected void onStart() {
  // TODO Auto-generated method stub
  super.onStart();

  MyDataBase mdb = new MyDataBase(ChooseMessageActivity.this);
  database = mdb.getWritableDatabase();
  cursor = database.rawQuery("select * from liushuibiao", null);
  listView1 = (ListView) findViewById(R.id.choosemessagelistView1);
  MyAdapter_FootSoft sca = new MyAdapter_FootSoft(ChooseMessageActivity.this,
    cursor);
  listView1.setAdapter(sca);
  listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

   /**
    * 根据用户选择不同的商品,向商品详细页面传递的参数不同。 arg2 为用户选择listview上的商品,序号从0开始 temp
    * 为id号 biaoming 为表名
    */
  
   public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
     long arg3) {

    int temp = arg2 + 1;
    intent = new Intent();
    intent.setClass(ChooseMessageActivity.this, MessageActivity.class);
    //intent.putExtra("id", liushuizhanghao);
    intent.putExtra("id", temp + "");
    startActivity(intent);
    finish();
   }
  });

 }

}

你可能感兴趣的:(MessageActivity)