文档介绍:Android编写一个检测标准体重的程序
package com・example. ex_10;
importjava・ text. DecimalFormat; importjava, text・ NumberFormat;
importandroid. app・ Activity; importandroid・ content・ Intent.; importandroid. os. Bundle; importandroid, view. View;
importandroid, widget. Button;importandroid. widget. TextView;
public class EX03_10_l extends Activity {
Intent intent;
//
©Override
protected void onCreate(Bundle savedInstancestate)
{ (savedinstanceState);
setConterUView(R・ );
intent 二 ;
Bundle bunde = intent. getExtrasO ;
String sex = bunde. getString("sex");
double height 二 bunde. getDouble("height");
String sexText ="“;
if (sex. equals("M")) {
sexText 二〃男性〃;
} else {
} sexText = 〃女性";} String weight 二 this. getWeight (sex, height) ; TextView tvl = (TextView) findViewById(R. id. textl) ; tvl. setText (z,你是一位"+ sex + "\n 你的身高是〃 +
height + 〃厘米\n你的标准体重是+ weight + 〃公斤”);Button bl二
(Button) findViewBylcKR. id. buttonl); bl. setOnClickListener(new
Button. OnClickListener() { public void onClick(View v)
{ EXO3_1O_1. this. setResult(RESULT_OK, intent); EX03_10_l. this, finish(): } }); private String format (double num) { NumberFormat. formatter = new
DocimalFormat(z/0・ 00") ; String s = formatter・fonn3t(rmm) ; return s; }} return weight;
private St ring t(St ring method stub } String weight 二“"; format((height - 80) *); }