</pre><pre name="code" class="java">package com.example.weight;
//import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import com.example.weight.R;
public class No1Activity extends Activity {
private Button button1;
private EditText edittext;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_no1);
button1 = (Button) findViewById(R.id.button1);
edittext = (EditText) findViewById(R.id.etname);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
String number = edittext.getText().toString();
int b = Integer.parseInt(number);
double weight1 = (b - 80) * 0.7;
double weight2 = (b - 70) * 0.6;
Intent intent = new Intent(No1Activity.this,
No2Activity.class);
RadioButton radioButton1 = (RadioButton) findViewById(R.id.radioButton1);
RadioButton radioButton2 = (RadioButton) findViewById(R.id.radioButton2);
boolean isChecked1 = radioButton1.isChecked();
boolean isChecked2 = radioButton2.isChecked();
if (isChecked1) {
intent.putExtra("sex", "你是一名" + radioButton1.getText()
+ "\n");
intent.putExtra("weight", "你的标准体重是" + weight1 + "千克\n");
}
if (isChecked2) {
intent.putExtra("sex", "你是一名" + radioButton2.getText()
+ "\n");
intent.putExtra("weight", "你的标准体重是" + weight2 + "千克\n");
}
intent.putExtra("height", "你的身高是" + number + "厘米" + "\n");
startActivity(intent);
}
});
}
}
package com.example.weight;
//import android.R;
import com.example.weight.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class No2Activity extends Activity {
private TextView textview;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_no2);
textview = (TextView) findViewById(R.id.textView2);
Intent intent = getIntent();
String sex = intent.getStringExtra("sex");
String height = intent.getStringExtra("height");
String weight = intent.getStringExtra("weight");
textview.setText(sex + height + weight);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/halou" >
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rd1_button" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rd2_button" />
</RadioGroup>
<requestFocus />
<EditText
android:id="@+id/etname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/radioGroup1"
android:layout_alignRight="@+id/textView1"
android:background="@android:drawable/edit_text"
android:ems="10"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="91dp"
android:text="@string/button1_name" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/etname"
android:layout_marginBottom="37dp"
android:layout_toLeftOf="@+id/radioGroup1"
android:text="@string/text2_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_marginBottom="44dp"
android:layout_toLeftOf="@+id/etname"
android:text="@string/text3_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/radioGroup1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="59dp"
android:text="@string/text1_name"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.weight"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".No1Activity"
android:label="标准体重计算器">
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".No2Activity">
</activity>
</application>
</manifest>