當前位置:首頁 » 安卓系統 » bmiandroid

bmiandroid

發布時間: 2025-04-11 02:15:32

A. 用android怎麼做計算BMI值得程序

應用的操作和原理

目標Android應用的操作過程是這樣的:選擇你的性別,然後輸入你的身高,點查看計算結果的按鈕就在Toast中顯示你的標准體重。力求操作簡單,結果顯示清楚。

標准體重的計算公式:

男性:(身高cm-80)×70%=標准體重

女性:(身高cm-70)×60%=標准體重

應用的源碼

BMIActivity.java

packagecom.ling.bmi;
importjava.text.DecimalFormat;
importjava.text.NumberFormat;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.RadioButton;
importandroid.widget.Toast;
/*
*@authorling*該程序的功能是用戶選擇自己的性別和輸入自己的身高,然後點擊按鈕,就能在Toast顯示出自己的標准體重
*/
{
/**.*/
privateButtoncountButton;
privateEditTextheighText;
privateRadioButtonmaleBtn,femaleBtn;
Stringsex="";
doubleheight;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//調用創建視圖的函數
creadView();
//調用性別選擇的函數
sexChoose();
//調用Button注冊監聽器的函數
setListener();
}
//響應Button事件的函數
privatevoidsetListener(){
countButton.setOnClickListener(countListner);
}
=newOnClickListener(){
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
Toast.makeText(BMIActivity.this,"你是一位"+sexChoose()+" "
+"你的身高為"+Double.parseDouble(heighText.getText().toString())+"cm"
+" 你的標准體重為"+getWeight(sexChoose(),height)+"kg",Toast.LENGTH_LONG)
.show();
}
};
//性別選擇的函數
privateStringsexChoose(){
if(maleBtn.isChecked()){
sex="男性";
}
elseif(femaleBtn.isChecked()){
sex="女性";
}
returnsex;
}
//創建視圖的函數
publicvoidcreadView(){
//txt=(TextView)findViewById(R.id.txt);
countButton=(Button)findViewById(R.id.btn);
heighText=(EditText)findViewById(R.id.etx);
maleBtn=(RadioButton)findViewById(R.id.male);
femaleBtn=(RadioButton)findViewById(R.id.female);
//txt.setBackgroundResource(R.drawable.bg);
}
//標准體重格式化輸出的函數
privateStringformat(doublenum){
NumberFormatformatter=newDecimalFormat("0.00");
Stringstr=formatter.format(num);
returnstr;
}
//得到標准體重的函數
privateStringgetWeight(Stringsex,doubleheight){
height=Double.parseDouble(heighText.getText().toString());
Stringweight="";
if(sex.equals("男性")){
weight=format((height-80)*0.7);
}
else{
weight=format((height-70)*0.6);
}
returnweight;
}
}
熱點內容
怎麼做雲腳本 發布:2025-04-25 23:37:17 瀏覽:543
怎麼配置serial窗口 發布:2025-04-25 23:32:24 瀏覽:963
java配置路徑 發布:2025-04-25 23:29:44 瀏覽:826
閃迪存儲卡g 發布:2025-04-25 23:24:51 瀏覽:211
c語言和It 發布:2025-04-25 23:18:22 瀏覽:695
c語言簡單程序設計 發布:2025-04-25 23:13:14 瀏覽:593
c語言編程思路 發布:2025-04-25 23:08:08 瀏覽:341
安卓開發存儲空間多少則為不足 發布:2025-04-25 22:54:55 瀏覽:541
視頻課堂源碼 發布:2025-04-25 22:52:55 瀏覽:982
庭院植物配置需要什麼 發布:2025-04-25 22:46:47 瀏覽:985