<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/first"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/second"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/start"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="start"
/>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="...is waiting"
/>
</LinearLayout>
first = (EditText) findViewById(R.id.first);
second = (EditText) findViewById(R.id.second);
public void startActivityForResult (Intent intent, int requestCode)
Intent intent:系统会根据这个确定目的Activity
int requestCode:用于标识该Intent 回来后确定是不是想要的返回
findViewById(R.id.start).setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
sendCalculate();
}
});
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/reply"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="reply"
/>
</LinearLayout>
Intent i = this.getIntent();
Bundle b = i.getExtras();
String v1 = b.getString("first");
String v2 = b.getString("second");
value = v1 + v2;
Intent i = new Intent();
Bundle b = new Bundle();
b.putString("CALCULATION", value);
i.putExtras(b);
this.setResult(RESULT_OK, i);
this.finish();
protected void onActivityResult(int requestCode, int resultCode,
Intent data){
switch (resultCode){
case RESULT_OK:
Bundle b = data.getExtras();
String string = b.getString("CALCULATION");
updateText(string);
}
}