开发实例:Android 身高计算器的实现
2010-05-24 00:03:00 来源:WEB开发网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();
}
});
}
}
main.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/widget28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="子女身高计算"
android:layout_x="76px"
android:layout_y="16px" >
< /TextView >
< TextView
更多精彩
赞助商链接