对应main.xml如下:
XML code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/factorOne"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/symbol"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<EditText
android:id="@+id/factorTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/calculate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
ResultActivity。java内容如下:
Java code
package mars.Activity03;
import android.app.Activity;import android.content.Intent;
import android.os.Bundle;import android.widget.TextView;
public class ResultActivity extends Activity{
private TextView resultView=null;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
System.out.println("resultActivity--error");
resultView=(TextView)findViewById(R.id.result);
Intent intent=getIntent();System.out.println("哪里错哦了!!");
String factorOneStr=intent.getStringExtra("one");
String factorTwoStr=intent.getStringExtra("Two");
int factorOneInt=Integer.parseInt(factorOneStr);
int factorTwoInt=Integer.parseInt(factorTwoStr);
int result=factorOneInt*factorTwoInt;
resultView.setText(result+"");
System.out.println("哪里错哦了!!--最后");
}
}
对应result.xml如下:
XML code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
string。xml如下:
XML code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Activity03!</string>
<string name="app_name">Activity03</string>
<string name="resultLabel">ResultActivity</string>
<string name="symbol">乘以</string>
<string name="calculate">计算</string>
</resources>
AndroidManifest.xml如下:
XML code<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
package="mars.Activity03"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Activity03"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ResultActivity" android:label="@string/resultLabel"></activity>
</application></manifest>
这里的two是小写
intent.putExtra("two", factorTwoStr);
这里的Two第一个字母是大写,所以得不到值,为空。
String factorTwoStr=intent.getStringExtra("Two");
大、 小写是有区别的噢。