Android 体重测仪器开发
2010-11-05 00:55:48 来源:WEB开发网return s;
}
/* 以findViewById()取得Button对象,并添加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;
}
}
package irdc.ex03_11;
/* import相关class */
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 EX03_11_1 extends Activity
{
Bundle bunde;
Intent intent;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* 载入mylayout.xml Layout */
setContentView(R.layout.myalyout);
/* 取得Intent中的Bundle对象 */
intent=this.getIntent();
bunde = intent.getExtras();
/* 取得Bundle对象中的数据 */
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 tv1=(TextView) findViewById(R.id.text1);
tv1.setText("你是一位"+sexText+" 你的身高是"+height+
更多精彩
赞助商链接