package com.example.ex_templete;
專注于為中小企業(yè)提供網(wǎng)站制作、網(wǎng)站建設(shè)服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)澠池免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了數(shù)千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。import java.text.DecimalFormat;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.ex_templete.R;
public class Bmi extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUI();
}
private void initUI() {
// Listen for button clicks
Button button = (Button) findViewById(R.id.submit);
button.setOnClickListener(calcBMI);
fieldheight = (EditText) findViewById(R.id.height);
fieldweight = (EditText) findViewById(R.id.weight);
result = (TextView) findViewById(R.id.result);
fieldsuggest = (TextView) findViewById(R.id.suggest);
}
private OnClickListener calcBMI = new OnClickListener() {
@Override
public void onClick(View v) {
DecimalFormat nf = new DecimalFormat("0.00");
double height = Double
.parseDouble(fieldheight.getText().toString()) / 100;
double weight = Double
.parseDouble(fieldweight.getText().toString());
double BMI = weight / (height * height);
result.setText("Your BMI is " + nf.format(BMI));
// Give health advice
if (BMI > 25) {
fieldsuggest.setText("太肥啦");
} else if (BMI < 20) {
fieldsuggest.setText("很骨感");
} else {
fieldsuggest.setText("身材不錯");
}
}
};
private EditText fieldheight;
private EditText fieldweight;
private TextView result;
private TextView fieldsuggest;
}
xml中只需要兩個editText,兩個textview,一個按鈕即可
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.ex_templete.MainActivity" >
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。