我正在使用两个 editText 框,例如“table no”和“no of guest”。如果我填充 editText 框并在 listView 中选择一些项目,然后转到下一个活动并再次返回上一个活动,其中 EditText 框可用,则值为空。我的要求是,当我回到上一个活动时,EditText 会显示我之前输入的数据。
发送编辑文本数据:
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//for (int i=0;i<GlobalClass.myval.length;i++){
//System .out.println("Clicked-->"+GlobalClass.myval[i]);
//}
String tno = e1.getText().toString();
int tn = Integer.parseInt(tno);
Intent i=new Intent(getApplicationContext(),TicketActivity.class);
Bundle b=new Bundle();
b.putInt("Table No:", tn);
i.putExtras(b);
String et= e2.getText().toString();
int et1 = Integer.parseInt(et);
Bundle be=new Bundle();
be.putInt("Guest:", et1);
i.putExtras(be);
startActivity(i);
}
});
第二个活动:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.ticket);
t1=(TextView)findViewById(R.id.textView3);
t2=(TextView)findViewById(R.id.textView5);
l1=(ListView)findViewById(R.id.listView1);
or=(ImageButton)findViewById(R.id.imageButton7);
ho=(ImageButton)findViewById(R.id.imageButton4);
de=(ImageButton)findViewById(R.id.imageButton1);
pl=(ImageButton)findViewById(R.id.imageButton2);
mi=(ImageButton)findViewById(R.id.imageButton3);
pa=(ImageButton)findViewById(R.id.imageButton5);
pr=(ImageButton)findViewById(R.id.imageButton6);
// l1.setItemsCanFocus(false);
//l1.setFocusable(true);
//l1.setClickable(true);
//Get the Table no Value From Edit Text
Intent i1=getIntent();
Bundle b=i1.getExtras();
int num=b.getInt("Table No:");
pno=Integer.toString(num);
t1.setText(pno);
//Get The Guest Value From Edit Text
Intent i2=getIntent();
Bundle b1=i2.getExtras();
int num1=b1.getInt("Guest:");
pno1=Integer.toString(num1);
t2.setText(pno1);
// List<String> st=GlobalClass.myval;
//ArrayAdapter<String> ada = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1,st);
l1.setAdapter(new EfficientAdapter(TicketActivity.this));
l1.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent,View view,int position,long id){
st2=HomeActivity.select1[position];
Toast.makeText(getApplicationContext(), "Selected:" + st2, Toast.LENGTH_SHORT).show();
}
});
//GO TO PREV ACTIVITY:
ho.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent o2=new Intent(TicketActivity.this,HomeActivity.class);
startActivity(o2);
}
});
}
}