close

匯入Android專案程式碼:

File>Import>Android>Exist Android Code (Copy)

如有更動XML,建議清除AAPT建立之檔案重新Build:

Project>Clean

 

AVD設定(使用含有Google Service之Google APIs)

AVD

原始碼-1

MainActivity01  

執行結果:

TextView>Auto Link>all (自動辨識)

android:textAppearance="?android:attr/textAppearanceLargeSmall" //設為小字,會依據解析度自動調整

20141217-2  

 

GenyMotion Android模擬器

https://www.genymotion.com/

 

程式碼:

package com.example.bmi;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

EditText et_height;
EditText et_weight;
TextView tv_result;
TextView tv_advice;
Button btn01;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn01 = (Button) findViewById(R.id.btn01);
btn01.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
float height = Float.parseFloat(et_height.getText().toString()) / 100;
float weight = Float.parseFloat(et_weight.getText().toString());
tv_result.setText("您的BMI值:" + (weight / (height * height)));
float BMI = weight / (height * height);
if (BMI <= 18.5) {
tv_result.setBackgroundColor(Color.YELLOW);
tv_result.setTextColor(Color.BLACK);
} else if (BMI > 18.5 && BMI < 24.9) {
tv_result.setBackgroundColor(Color.GREEN);
tv_result.setTextColor(Color.BLACK);
} else if (BMI > 25 && BMI < 29) {
tv_result.setBackgroundColor(0xffff7777);
tv_result.setTextColor(Color.BLACK);
} else if (BMI > 29 && BMI < 32) {
tv_result.setBackgroundColor(Color.RED);
tv_result.setTextColor(Color.BLACK);
tv_advice.setText(
"減重門診官網:http://www.weightwatcher.co.uk \n\n"+
"請來電:(02)2788-9188 \n\n"+
"請電郵:henryho85@gmail.com\n\n"+
"診所位置:https://www.google.com.tw/maps/search/%E6%B8%9B%E9%87%8D/@25.0419441,121.5432087,15z?hl=zh-TW");
} else if (BMI > 33) {
tv_result.setBackgroundColor(Color.BLACK);
tv_result.setTextColor(Color.RED);
tv_advice.setText(
"減重門診官網:\n http://www.weightwatcher.co.uk \n"+
"請來電:\n (02)2788-9188 \n"+
"請電郵:\n henryho85@gmail.com\n"+
"診所位置:\n https://www.google.com.tw/maps/search/%E6%B8%9B%E9%87%8D/@25.0419441,121.5432087,15z?hl=zh-TW");

}
}

});
et_height = (EditText) findViewById(R.id.et_height);
et_weight = (EditText) findViewById(R.id.et_weight);
tv_result = (TextView) findViewById(R.id.tv_result);
tv_advice = (TextView) findViewById(R.id.tv_advice);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 鈴木保齡球 的頭像
    鈴木保齡球

    Java程式學習手札

    鈴木保齡球 發表在 痞客邦 留言(0) 人氣()