startActivityForResult 的利用
1. 跳转新的Activity方法
public void bt1(View view){
Toast.makeText(this, "bu1", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, v2.class);
startActivityForResult(intent, 99);
}
2. 回调方法
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String ss = data.getStringExtra("a").toString();
((EditText) findViewById(R.id.editText1)).setText(ss);
String b = data.getStringExtra("b").toString();
String c = data.getStringExtra("c").toString();
Toast.makeText(this, b, Toast.LENGTH_SHORT).show();
this.setTitle(c);
}
3. 从新的Activity返回值的的方法
public void bu2(View view){
EditText et = (EditText) findViewById(R.id.editText);
Intent intent = new Intent();
intent.putExtra("a", et.getText().toString());
intent.putExtra("b", "bbbbbb");
intent.putExtra("c", "cccccc");
setResult(88,intent);
this.finish();
}
0 件のコメント:
コメントを投稿