日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Android開(kāi)發(fā):標(biāo)準(zhǔn)體重計(jì)算器應(yīng)用的開(kāi)發(fā)實(shí)例

應(yīng)用的操作和原理

目標(biāo)Android應(yīng)用的操作過(guò)程是這樣的:選擇你的性別,然后輸入你的身高,點(diǎn)查看計(jì)算結(jié)果的按鈕就在Toast中顯示你的標(biāo)準(zhǔn)體重。力求操作簡(jiǎn)單,結(jié)果顯示清楚。

標(biāo)準(zhǔn)體重的計(jì)算公式:

男性:(身高cm-80)×70﹪=標(biāo)準(zhǔn)體重

女性:(身高cm-70)×60﹪=標(biāo)準(zhǔn)體重

應(yīng)用的源碼

BMIActivity.java:

 
 
 
  1. package com.lingdududu.bmi;    
  2. import java.text.DecimalFormat;    
  3. import java.text.NumberFormat;    
  4. import android.app.Activity;    
  5. import android.os.Bundle;    
  6. import android.view.View;    
  7. import android.view.View.OnClickListener;    
  8. import android.widget.Button;     
  9. import android.widget.EditText;    
  10. import android.widget.RadioButton;    
  11. import android.widget.Toast;      
  12. /*   
  13. * @author lingdududu * 該程序的功能是用戶選擇自己的性別和輸入自己的身高,然后點(diǎn)擊按鈕,就能在Toast顯示出自己的標(biāo)準(zhǔn)體重   
  14. */   
  15. public class BMIActivity extends Activity {    
  16. /** Called when the activity is first created. */   
  17.     private Button countButton;      
  18.     private EditText heighText;      
  19.     private RadioButton maleBtn, femaleBtn;       
  20.     String sex = "";      
  21.     double height;      
  22.     @Override     
  23.     public void onCreate(Bundle savedInstanceState) {      
  24.         super.onCreate(savedInstanceState);      
  25.         setContentView(R.layout.main);      
  26.         //調(diào)用創(chuàng)建視圖的函數(shù)      
  27.         creadView();      
  28.         //調(diào)用性別選擇的函數(shù)      
  29.         sexChoose();      
  30.         //調(diào)用Button注冊(cè)監(jiān)聽(tīng)器的函數(shù)      
  31.         setListener();      
  32.    }      
  33.     //響應(yīng)Button事件的函數(shù)      
  34.     private void setListener() {      
  35.         countButton.setOnClickListener(countListner);      
  36.     }      
  37.     private OnClickListener countListner = new OnClickListener() {      
  38.         @Override     
  39.         public void onClick(View v) {      
  40.             // TODO Auto-generated method stub      
  41.             Toast.makeText(BMIActivity.this, "你是一位"+sexChoose()+"\n"     
  42.                            +"你的身高為"+Double.parseDouble(heighText.getText().toString())+"cm"     
  43.                            +"\n你的標(biāo)準(zhǔn)體重為"+getWeight(sexChoose(), height)+"kg", Toast.LENGTH_LONG)      
  44.                            .show();      
  45.         }      
  46.     };      
  47.     //性別選擇的函數(shù)      
  48.     private String sexChoose(){           
  49.         if (maleBtn.isChecked()) {      
  50.             sex = "男性";      
  51.         }       
  52.         else if(femaleBtn.isChecked()){      
  53.             sex = "女性";      
  54.         }      
  55.         return sex;           
  56.     }      
  57.     //創(chuàng)建視圖的函數(shù)      
  58.     public void creadView(){      
  59.         //txt=(TextView)findViewById(R.id.txt);      
  60.         countButton=(Button)findViewById(R.id.btn);      
  61.         heighText=(EditText)findViewById(R.id.etx);      
  62.         maleBtn=(RadioButton)findViewById(R.id.male);      
  63.         femaleBtn=(RadioButton)findViewById(R.id.female);         
  64.         //txt.setBackgroundResource(R.drawable.bg);      
  65.     }      
  66.     //標(biāo)準(zhǔn)體重格式化輸出的函數(shù)      
  67.     private String format(double num) {   
  68.         NumberFormat formatter = new DecimalFormat("0.00");      
  69.         String str = formatter.format(num);      
  70.         return str;      
  71.         }      
  72.     //得到標(biāo)準(zhǔn)體重的函數(shù)      
  73.     private String getWeight(String sex, double height) {      
  74.         height = Double.parseDouble(heighText.getText().toString());      
  75.         String weight = "";      
  76.         if (sex.equals("男性")) {      
  77.               weight =format((height - 80) * 0.7);      
  78.         }       
  79.         else {      
  80.               weight = format((height - 70) * 0.6);      
  81.         }      
  82.         return weight;      
  83.        }      
  84.    }     

別走開(kāi),下頁(yè)為您帶來(lái)main.xml與體重計(jì)算器應(yīng)用效果圖展示

#p#

main.xml:

 
 
 
  1.      
  2.     android:orientation="vertical"     
  3.     android:layout_width="fill_parent"     
  4.     android:layout_height="fill_parent"     
  5.     android:background="@drawable/pic"     
  6.     >     
  7.     
  8.         android:id="@+id/txt"     
  9.         android:layout_width="fill_parent"       
  10.         android:layout_height="wrap_content"       
  11.         android:gravity="center"       
  12.         android:text="@string/hello"     
  13.         android:textSize="16px"       
  14.         />     
  15.    
  16.         android:layout_width="fill_parent"       
  17.         android:layout_height="wrap_content"       
  18.         android:text="@string/sex"         
  19.         />     
  20.    
  21.       android:layout_width="fill_parent"       
  22.       android:layout_height="wrap_content"       
  23.       android:orientation="horizontal"     
  24.       >        
  25.       
  26.            android:id="@+id/male"     
  27.            android:layout_width="wrap_content"       
  28.            android:layout_height="wrap_content"       
  29.            android:text="男"       
  30.            />       
  31.       
  32.            android:id="@+id/female"     
  33.            android:layout_width="wrap_content"       
  34.            android:layout_height="wrap_content"     
  35.            android:text="女"       
  36.            />       
  37.           
  38.    
  39.         android:layout_width="fill_parent"       
  40.         android:layout_height="26px"     
  41.         android:text="@string/heigh"     
  42.         />     
  43.    
  44.         android:id="@+id/etx"     
  45.         android:layout_width="fill_parent"       
  46.         android:layout_height="wrap_content"       
  47.         />     
  48.    
  49.          android:id="@+id/btn"     
  50.          android:layout_width="fill_parent"       
  51.          android:layout_height="wrap_content"     
  52.          android:text="@string/count"     
  53.          />     
  54.     

應(yīng)用效果圖

大家可以根據(jù)其他復(fù)雜的標(biāo)準(zhǔn)體重計(jì)算器繼續(xù)完善此應(yīng)用,使其成為一個(gè)可用的、美觀的Android應(yīng)用。


當(dāng)前文章:Android開(kāi)發(fā):標(biāo)準(zhǔn)體重計(jì)算器應(yīng)用的開(kāi)發(fā)實(shí)例
URL標(biāo)題:http://www.dlmjj.cn/article/dpsjsee.html