mainactivity
private Button button1;
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1=(Button) findViewById(R.id.button1);
final EditText edittest=(EditText) findViewById(R.id.editText1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
String gaodu=edittest.getText().toString();
int b=Integer.parseInt(gaodu);
double duoshaokg1=(b-80)*(0.7);
double duoshaokg2=(b-70)*(0.6);
Intent intent=new Intent(MainActivity.this,ShowActivity.class);
RadioButton radioButton1=(RadioButton) findViewById(R.id.radioButton1);
RadioButton radioButton2=(RadioButton) findViewById(R.id.radioButton2);
boolean clink1 = radioButton1.isChecked();
boolean clink2 = radioButton2.isChecked();
if(clink1)
{
intent.putExtra("sex","你是"+radioButton1.getText()+"性\n");
intent.putExtra("weight", "你的标准体重是"+duoshaokg1+"公斤");
}
if(clink2)
{
intent.putExtra("sex","你是"+radioButton2.getText()+"性\n");
intent.putExtra("weight", "你的标准体重是"+duoshaokg2+"公斤");
}
intent.putExtra("height", "你的身高是" + gaodu + "厘米\n");
startActivity(intent);
}
});
showactivity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
TextView textview =(TextView) this.findViewById(R.id.textView1);
Intent intent =getIntent();
String sex =intent.getStringExtra("sex");
String height =intent.getStringExtra("height");
String weight =intent.getStringExtra("weight");
textview.setText(sex+height+weight);
}
main.xml
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView2"
android:layout_centerVertical="true"
android:text="@string/Button" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignLeft="@+id/textView1"
android:layout_marginBottom="16dp"
android:text="@string/TextView2" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/textView2"
android:ems="10" >
<requestFocus />
</EditText>
<RadioGroup
android:id="@+id/genderGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_alignTop="@+id/textView1"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/RadioButton2" />
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/RadioButton1" />
</RadioGroup>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/editText1"
android:layout_marginBottom="26dp"
android:text="@string/TextView" />
show.xml
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
android:textAppearance="?android:attr/textAppearanceLarge" />