//Activity_Main 代碼
public class Menuer extends Activity {
protected static final int REQUEST_CODE = 0;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
tv=(TextView) findViewById(R.id.tv1);
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getBaseContext(),Activity_A.class);
startActivityForResult(i,REQUEST_CODE);
}
});
}
protected void onActivityResult(int requestCode,int resultCode, Intent i)
{
if(requestCode == REQUEST_CODE)
{
if(resultCode ==RESULT_OK)
{
Bundle bundle = i.getExtras();
final String name = bundle.getString("name");
final String sex = bundle.getString("sex");
final String age = bundle.getString("age");
tv.setText("Your messages as follow: \n" + "name: " + name +"\n sex: " + sex + "\n age: " + age);
}
}
super.onActivityResult(0, 0, i);
}
//Activity_A 代碼
public class Activity_A extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a);
EditText name_in = (EditText) findViewById(R.id.name_in);
EditText sex_in = (EditText) findViewById(R.id.sex_in);
EditText age_in = (EditText) findViewById(R.id.age_in);
final String name = name_in.getText().toString();
final String sex = sex_in.getText().toString();
final String age = age_in.getText().toString();
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent();
Bundle bundle = new Bundle();
bundle.putString("name",name);
bundle.putString("sex", sex);
bundle.putString("age", age);
i.putExtras(bundle);
setResult(RESULT_OK,i);
finish();
}
});
}
}
你的代碼在我的浏覽器顯示有點問題,請參考我的博客:http://blog.csdn.net/afandaafandaafanda/article/details/41594125,希望能幫助到你。