Activity1.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Absolutelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Id = "@ + ID/widget0"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Textview
Android: Id = "@ + ID/Title"
Android: layout_width = "243px"
Android: layout_height = "29px"
Android: text = "@ string/Title"
Android: textsize = "24sp"
Android: layout_x = "36px"
Android: layout_y = "32px"
/>
<Textview
Android: Id = "@ + ID/text1"
Android: layout_width = "wrap_content"
Android: layout_height = "37px"
Android: text = "@ string/text1"
Android: textsize = "18sp"
Android: layout_x = "40px"
Android: layout_y = "156px"
/>
<Textview
Android: Id = "@ + ID/text2"
Android: layout_width = "wrap_content"
Android: layout_height = "29px"
Android: text = "@ string/text2"
Android: textsize = "18sp"
Android: layout_x = "40px"
Android: layout_y = "102px"
/>
<Textview
Android: Id = "@ + ID/text3"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "cm"
Android: textsize = "18sp"
Android: layout_x = "231px"
Android: layout_y = "157px"
/>
<Button
Android: Id = "@ + ID/button1"
Android: layout_width = "70px"
Android: layout_height = "48px"
Android: layout_x = "130px"
Android: layout_y = "232px"
Android: text = "computing"
/>
<Radiogroup
Android: Id = "@ + ID/sex"
Android: layout_width = "300px"
Android: layout_height = "100px"
Xmlns: Android = "http://schemax.android.com/apk/res/android"
Android: layout_x = "97px"
Android: layout_y = "98px"
Android: Orientation = "horizontal"
Android: checkedbutton = "@ + ID/sex1">
<Radiobutton
Android: Id = "@ + ID/sex1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "male"
/>
<Radiobutton
Android: Id = "@ + ID/sex2"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "female"
/>
</Radiogroup>
<Edittext
Android: Id = "@ + ID/height"
Android: layout_width = "130px"
Android: layout_height = "wrap_content"
Android: textsize = "18sp"
Android: layout_x = "96px"
Android: layout_y = "142px"
Android: Numeric = "decimal">
</Edittext>"
</Absolutelayout>
Activity2.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Absolutelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Textview
Android: Id = "@ + ID/text1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textsize = "20sp"
Android: layout_x = "50px"
Android: layout_y = "72px"
/>
</Absolutelayout>
Activity1.java
Package com. Bund;
Import Android. App. activity;
Import Android. content. intent;
Import
Android. OS. Bundle;
Import Android. View. view;
Import
Android. widget. Button;
Import Android. widget. edittext;
Import
Android. widget. radiobutton;
Public class activity1 extends activity {
/** Called when the activity is
First created .*/
@ Override
Public void oncreate (bundle
Savedinstancestate)
{
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity1 );
Button
B1 = (button) findviewbyid (R. Id. button1 );
B1.setonclicklistener (New
Button. onclicklistener (){
@ Override
Public void onclick (view v ){
// Get the entered height
Edittext ET =
(Edittext) findviewbyid (R. Id. Height );
Double Height =
Double. parsedouble (ET. gettext (). tostring ());
// Obtain the Selected Gender
String sex =
"";
Radiobutton P4 = (radiobutton)
Findviewbyid (R. Id. sex1 );
If (rb1.ischecked ()){
Sex = "M ";
} Else {
Sex
= "F ";
}
Intent intent = new
Intent ();
Intent. setclass (activity1.this, activity2.class );
// New
A bundle object and the data to be passed in
Bundle bundle = new
Bundle ();
Bundle. putdouble ("height", height );
Bundle. putstring ("sex ",
Sex );
// Assign the bundle object assign to intent
Intent. putextras (bundle );
// Call activity2
Startactivity (intent );
}
});
}
}
Activity2.java
Package com. Bund;
Import java. Text. decimalformat;
Import java. Text. numberformat;
Import
Android. App. activity;
Import Android. OS. Bundle;
Import
Android. widget. textview;
Public class activity2 extends activity {
@ Override
Protected void oncreate (bundle savedinstancestate ){
// Todo
Auto-generated Method
Stub
Super. oncreate (savedinstancestate );
// Load activity2.xml
Setcontentview (R. layout. activity2 );
// Obtain the bundle object in intent
Bundle
Bunde = This. getintent (). getextras ();
// Obtain data in the bundle object
String sex =
Bunde. getstring ("sex ");
Double Height =
Bunde. getdouble ("height ");
// Determine gender
String sextext = "";
If (
Sex. Equals ("M ")){
Sextext = "male ";
} Else {
Sextext =
"Female ";
}
// Get the standard weight
String Weight = This. getweight (sex,
Height );
// Set the input text
Textview TV1 = (textview)
Findviewbyid (R. Id. text1 );
Tv1.settext ("You are a person" + sextext + "\ n your height is" + height +
"CM \ n your standard weight is" + weight + "kg ");
}
// Rounding
Private string format (double
Num ){
Numberformatter = new decimalformat ("0.00 ");
String S =
Formatter. Format (Num );
Return
S;
}
// Obtain the button object with findviewbyid () and add onclicklistener
Private string
Getweight (string sex, double height ){
String Weight =
"";
If (sex. Equals ("M ")){
Weight =
Format (height-80) * 0.7 );
} Else {
Weight =
Format (height-70) * 0.6 );
}
Return weight;
}
}
Activity1.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Absolutelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Id = "@ + ID/widget0"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Textview
Android: Id = "@ + ID/Title"
Android: layout_width = "243px"
Android: layout_height = "29px"
Android: text = "@ string/Title"
Android: textsize = "24sp"
Android: layout_x = "36px"
Android: layout_y = "32px"
/>
<Textview
Android: Id = "@ + ID/text1"
Android: layout_width = "wrap_content"
Android: layout_height = "37px"
Android: text = "@ string/text1"
Android: textsize = "18sp"
Android: layout_x = "40px"
Android: layout_y = "156px"
/>
<Textview
Android: Id = "@ + ID/text2"
Android: layout_width = "wrap_content"
Android: layout_height = "29px"
Android: text = "@ string/text2"
Android: textsize = "18sp"
Android: layout_x = "40px"
Android: layout_y = "102px"
/>
<Textview
Android: Id = "@ + ID/text3"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "cm"
Android: textsize = "18sp"
Android: layout_x = "231px"
Android: layout_y = "157px"
/>
<Button
Android: Id = "@ + ID/button1"
Android: layout_width = "70px"
Android: layout_height = "48px"
Android: layout_x = "130px"
Android: layout_y = "232px"
Android: text = "computing"
/>
<Radiogroup
Android: Id = "@ + ID/sex"
Android: layout_width = "300px"
Android: layout_height = "100px"
Xmlns: Android = "http://schemax.android.com/apk/res/android"
Android: layout_x = "97px"
Android: layout_y = "98px"
Android: Orientation = "horizontal"
Android: checkedbutton = "@ + ID/sex1">
<Radiobutton
Android: Id = "@ + ID/sex1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "male"
/>
<Radiobutton
Android: Id = "@ + ID/sex2"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "female"
/>
</Radiogroup>
<Edittext
Android: Id = "@ + ID/height"
Android: layout_width = "130px"
Android: layout_height = "wrap_content"
Android: textsize = "18sp"
Android: layout_x = "96px"
Android: layout_y = "142px"
Android: Numeric = "decimal">
</Edittext>"
</Absolutelayout>
Activity2.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Absolutelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Textview
Android: Id = "@ + ID/text1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textsize = "20sp"
Android: layout_x = "50px"
Android: layout_y = "72px"
/>
</Absolutelayout>
Activity1.java
Package com. Bund;
Import Android. App. activity;
Import Android. content. intent;
Import
Android. OS. Bundle;
Import Android. View. view;
Import
Android. widget. Button;
Import Android. widget. edittext;
Import
Android. widget. radiobutton;
Public class activity1 extends activity {
/** Called when the activity is
First created .*/
@ Override
Public void oncreate (bundle
Savedinstancestate)
{
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity1 );
Button
B1 = (button) findviewbyid (R. Id. button1 );
B1.setonclicklistener (New
Button. onclicklistener (){
@ Override
Public void onclick (view v ){
// Get the entered height
Edittext ET =
(Edittext) findviewbyid (R. Id. Height );
Double Height =
Double. parsedouble (ET. gettext (). tostring ());
// Obtain the Selected Gender
String sex =
"";
Radiobutton P4 = (radiobutton)
Findviewbyid (R. Id. sex1 );
If (rb1.ischecked ()){
Sex = "M ";
} Else {
Sex
= "F ";
}
Intent intent = new
Intent ();
Intent. setclass (activity1.this, activity2.class );
// New
A bundle object and the data to be passed in
Bundle bundle = new
Bundle ();
Bundle. putdouble ("height", height );
Bundle. putstring ("sex ",
Sex );
// Assign the bundle object assign to intent
Intent. putextras (bundle );
// Call activity2
Startactivity (intent );
}
});
}
}
Activity2.java
Package com. Bund;
Import java. Text. decimalformat;
Import java. Text. numberformat;
Import
Android. App. activity;
Import Android. OS. Bundle;
Import
Android. widget. textview;
Public class activity2 extends activity {
@ Override
Protected void oncreate (bundle savedinstancestate ){
// Todo
Auto-generated Method
Stub
Super. oncreate (savedinstancestate );
// Load activity2.xml
Setcontentview (R. layout. activity2 );
// Obtain the bundle object in intent
Bundle
Bunde = This. getintent (). getextras ();
// Obtain data in the bundle object
String sex =
Bunde. getstring ("sex ");
Double Height =
Bunde. getdouble ("height ");
// Determine gender
String sextext = "";
If (
Sex. Equals ("M ")){
Sextext = "male ";
} Else {
Sextext =
"Female ";
}
// Get the standard weight
String Weight = This. getweight (sex,
Height );
// Set the input text
Textview TV1 = (textview)
Findviewbyid (R. Id. text1 );
Tv1.settext ("You are a person" + sextext + "\ n your height is" + height +
"CM \ n your standard weight is" + weight + "kg ");
}
// Rounding
Private string format (double
Num ){
Numberformatter = new decimalformat ("0.00 ");
String S =
Formatter. Format (Num );
Return
S;
}
// obtain the button object with findviewbyid () and add onclicklistener
private string
getweight (string sex, double height) {
string Weight =
"";
If (sex. equals ("M") {
Weight =
Format (height-80) * 0.7 );
}else {
Weight =
Format (height-70) * 0.6);
}< br> return weight;
}< BR >}