Android 身高计算
代码
package app.test;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
public class test extends Activity
{
/** Called when the activity is first created. */
private Button mButton;
private EditText fEeditText;
private EditText mEeditText;
private RadioGroup mRadioGroup;
private double fheight;
private double mheight;
private String Sex;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton=(Button)findViewById(R.id.confirm);
fEeditText=(EditText)findViewById(R.id.fheigt);
mEeditText=(EditText)findViewById(R.id.mheigt);
mButton.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
if(fEeditText.getText().toString().length()<1)
{
Builder adia=new AlertDialog.Builder(test.this);
adia.setMessage("请輸入父亲的身高");
adia.setTitle("提示");
adia.setNeutralButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
fEeditText.setHighlightColor(Color.RED);
}
});
adia.show();
return;
}
if(mEeditText.getText().toString().length()<1)
{
Builder adia=new AlertDialog.Builder(test.this);
adia.setMessage("请输入母亲的身高");
adia.setTitle("提示");
adia.setNeutralButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
mEeditText.setHighlightColor(Color.RED);
}
});
adia.show();
return;
}
mRadioGroup=(RadioGroup)findViewById(R.id.sex);
if(mRadioGroup.getCheckedRadioButtonId()==R.id.F)
{Sex="女孩";}
else
{
Sex="男孩";
}
Intent intent=new Intent();
intent.setClass(test.this,result.class);
fheight=Double.parseDouble(fEeditText.getText().toString());
mheight=Double.parseDouble(mEeditText.getText().toString());
Bundle bun=new Bundle();
bun.putDouble("fheight", fheight);
bun.putDouble("mheight", mheight);
bun.putString("Sex", Sex);
intent.putExtras(bun);
startActivity(intent);
finish();
// BundleObject.this.finish();
}
});
}
}
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
public class test extends Activity
{
/** Called when the activity is first created. */
private Button mButton;
private EditText fEeditText;
private EditText mEeditText;
private RadioGroup mRadioGroup;
private double fheight;
private double mheight;
private String Sex;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton=(Button)findViewById(R.id.confirm);
fEeditText=(EditText)findViewById(R.id.fheigt);
mEeditText=(EditText)findViewById(R.id.mheigt);
mButton.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
if(fEeditText.getText().toString().length()<1)
{
Builder adia=new AlertDialog.Builder(test.this);
adia.setMessage("请輸入父亲的身高");
adia.setTitle("提示");
adia.setNeutralButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
fEeditText.setHighlightColor(Color.RED);
}
});
adia.show();
return;
}
if(mEeditText.getText().toString().length()<1)
{
Builder adia=new AlertDialog.Builder(test.this);
adia.setMessage("请输入母亲的身高");
adia.setTitle("提示");
adia.setNeutralButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
mEeditText.setHighlightColor(Color.RED);
}
});
adia.show();
return;
}
mRadioGroup=(RadioGroup)findViewById(R.id.sex);
if(mRadioGroup.getCheckedRadioButtonId()==R.id.F)
{Sex="女孩";}
else
{
Sex="男孩";
}
Intent intent=new Intent();
intent.setClass(test.this,result.class);
fheight=Double.parseDouble(fEeditText.getText().toString());
mheight=Double.parseDouble(mEeditText.getText().toString());
Bundle bun=new Bundle();
bun.putDouble("fheight", fheight);
bun.putDouble("mheight", mheight);
bun.putString("Sex", Sex);
intent.putExtras(bun);
startActivity(intent);
finish();
// BundleObject.this.finish();
}
});
}
}
代码
package app.test;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class result extends Activity {
String Sex;
double fheight;
double mheight;
double cheight;
private TextView mTextView01;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlayout);
Bundle bun=this.getIntent().getExtras();
Sex=bun.getString("Sex");
fheight=bun.getDouble("fheight");
mheight=bun.getDouble("mheight");
mTextView01=(TextView)findViewById(R.id.TextView01);
NumberFormat formatter=new DecimalFormat("0.00");
if(Sex.equals("女孩"))
{
cheight=(fheight*0.923+mheight)/2;
mTextView01.setText(Sex+"身高预测为 :"+formatter.format(cheight));
}
else
{
cheight=(fheight+mheight)*1.08/2;
mTextView01.setText(Sex+"身高预测为:"+formatter.format(cheight));
}
Button mButton = (Button)findViewById(R.id.ButtonReturn);
mButton.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent=new Intent();
intent.setClass(result.this,test.class);
startActivity(intent);
finish();
}
});
}
}
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class result extends Activity {
String Sex;
double fheight;
double mheight;
double cheight;
private TextView mTextView01;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlayout);
Bundle bun=this.getIntent().getExtras();
Sex=bun.getString("Sex");
fheight=bun.getDouble("fheight");
mheight=bun.getDouble("mheight");
mTextView01=(TextView)findViewById(R.id.TextView01);
NumberFormat formatter=new DecimalFormat("0.00");
if(Sex.equals("女孩"))
{
cheight=(fheight*0.923+mheight)/2;
mTextView01.setText(Sex+"身高预测为 :"+formatter.format(cheight));
}
else
{
cheight=(fheight+mheight)*1.08/2;
mTextView01.setText(Sex+"身高预测为:"+formatter.format(cheight));
}
Button mButton = (Button)findViewById(R.id.ButtonReturn);
mButton.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent=new Intent();
intent.setClass(result.this,test.class);
startActivity(intent);
finish();
}
});
}
}
代码
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/widget28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="子女身高计算"
android:layout_x="76px"
android:layout_y="16px">
</TextView>
<TextView
android:id="@+id/widget29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别"
android:layout_x="22px"
android:layout_y="54px"
>
</TextView>
<RadioGroup
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="67px"
android:layout_y="45px"
android:gravity="center_horizontal"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/M"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="@+id/F"
android:checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
/>
</RadioGroup>
<TextView
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="父亲身高(cm)"
android:layout_x="0px"
android:layout_y="89px"
>
</TextView>
<EditText
android:id="@+id/fheigt"
android:layout_width="200px"
android:layout_height="40px"
android:text=""
android:numeric="decimal"
android:textSize="18sp"
android:layout_x="96px"
android:layout_y="85px"
>
</EditText>
<TextView
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="母亲身高(cm)"
android:layout_x="0px"
android:layout_y="129px"
>
</TextView>
<EditText
android:id="@+id/mheigt"
android:layout_width="200px"
android:layout_height="40px"
android:text=""
android:numeric="decimal"
android:textSize="18sp"
android:layout_x="96px"
android:layout_y="129px"
>
</EditText>
<Button
android:id="@+id/confirm"
android:layout_width="105px"
android:layout_height="wrap_content"
android:text="计算"
android:layout_x="122px"
android:layout_y="182px"
>
</Button>
</AbsoluteLayout>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/widget28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="子女身高计算"
android:layout_x="76px"
android:layout_y="16px">
</TextView>
<TextView
android:id="@+id/widget29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别"
android:layout_x="22px"
android:layout_y="54px"
>
</TextView>
<RadioGroup
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="67px"
android:layout_y="45px"
android:gravity="center_horizontal"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/M"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="@+id/F"
android:checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
/>
</RadioGroup>
<TextView
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="父亲身高(cm)"
android:layout_x="0px"
android:layout_y="89px"
>
</TextView>
<EditText
android:id="@+id/fheigt"
android:layout_width="200px"
android:layout_height="40px"
android:text=""
android:numeric="decimal"
android:textSize="18sp"
android:layout_x="96px"
android:layout_y="85px"
>
</EditText>
<TextView
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="母亲身高(cm)"
android:layout_x="0px"
android:layout_y="129px"
>
</TextView>
<EditText
android:id="@+id/mheigt"
android:layout_width="200px"
android:layout_height="40px"
android:text=""
android:numeric="decimal"
android:textSize="18sp"
android:layout_x="96px"
android:layout_y="129px"
>
</EditText>
<Button
android:id="@+id/confirm"
android:layout_width="105px"
android:layout_height="wrap_content"
android:text="计算"
android:layout_x="122px"
android:layout_y="182px"
>
</Button>
</AbsoluteLayout>
mainlayout.xml
代码
<?xml version="1.0" encoding="UTF-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="18px"
>
</TextView>
<Button
android:id="@+id/ButtonReturn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="137px"
android:layout_y="120px"
android:text="返回"
>
</Button>
</AbsoluteLayout>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="18px"
>
</TextView>
<Button
android:id="@+id/ButtonReturn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="137px"
android:layout_y="120px"
android:text="返回"
>
</Button>
</AbsoluteLayout>