...
class Ex03_11
...
/* 覆盖onActivityResult()*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (resultCode)
{
case RESULT_OK:
/* 取得Activity2的数据,并显示在画面上*/
Bundle bunde = data.getExtras();
String sex = bunde.getString("sex");
double height = bunde.getDouble("height");
et.setText(""+height);
if(sex.equals("M"))
{
rb1.setChecked(true);
}else
{
rb2.setChecked(true);
}
break;
default:
break;
}
}
class Ex03_11_1
...
/*以findViewById()取得Button对象,并添加onClickListener */
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
/*返回result回上一个activity */
EX03_11_1.this.setResult(RESULT_OK, intent);
/* 结束这个activity */
EX03_11_1.this.finish();
}
});
...