diff --git a/.gradle/4.6/fileHashes/fileHashes.bin b/.gradle/4.6/fileHashes/fileHashes.bin
index 7fe9893..f7e3791 100644
Binary files a/.gradle/4.6/fileHashes/fileHashes.bin and b/.gradle/4.6/fileHashes/fileHashes.bin differ
diff --git a/.gradle/4.6/fileHashes/fileHashes.lock b/.gradle/4.6/fileHashes/fileHashes.lock
index b25322e..eb595d9 100644
Binary files a/.gradle/4.6/fileHashes/fileHashes.lock and b/.gradle/4.6/fileHashes/fileHashes.lock differ
diff --git a/.gradle/4.6/javaCompile/classAnalysis.bin b/.gradle/4.6/javaCompile/classAnalysis.bin
index d55ee3d..374ddf9 100644
Binary files a/.gradle/4.6/javaCompile/classAnalysis.bin and b/.gradle/4.6/javaCompile/classAnalysis.bin differ
diff --git a/.gradle/4.6/javaCompile/javaCompile.lock b/.gradle/4.6/javaCompile/javaCompile.lock
index c3ce6ee..f53547c 100644
Binary files a/.gradle/4.6/javaCompile/javaCompile.lock and b/.gradle/4.6/javaCompile/javaCompile.lock differ
diff --git a/.gradle/4.6/javaCompile/taskHistory.bin b/.gradle/4.6/javaCompile/taskHistory.bin
index 5f13bb2..9be2f53 100644
Binary files a/.gradle/4.6/javaCompile/taskHistory.bin and b/.gradle/4.6/javaCompile/taskHistory.bin differ
diff --git a/.gradle/4.6/taskHistory/taskHistory.bin b/.gradle/4.6/taskHistory/taskHistory.bin
index 399e40f..15c8025 100644
Binary files a/.gradle/4.6/taskHistory/taskHistory.bin and b/.gradle/4.6/taskHistory/taskHistory.bin differ
diff --git a/.gradle/4.6/taskHistory/taskHistory.lock b/.gradle/4.6/taskHistory/taskHistory.lock
index 97d5726..92be427 100644
Binary files a/.gradle/4.6/taskHistory/taskHistory.lock and b/.gradle/4.6/taskHistory/taskHistory.lock differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index 116017d..1441701 100644
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bdc0187..54e84d7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -11,7 +11,12 @@
-
+
+
+
+
+
+
@@ -32,13 +37,13 @@
-
-
+
+
-
+
-
+
@@ -52,17 +57,20 @@
-
+
-
-
+
+
+
+
+
-
-
+
+
-
+
+
-
+
@@ -2360,8 +2370,8 @@
+
-
@@ -2495,48 +2505,63 @@
-
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -2548,11 +2573,18 @@
+
+
+
-
-
+
+
+
+
+
+
diff --git a/app/src/main/java/me/jj97181818/ch06_energycalculator/MainActivity.java b/app/src/main/java/me/jj97181818/ch06_energycalculator/MainActivity.java
index 23347b1..a50eb2c 100644
--- a/app/src/main/java/me/jj97181818/ch06_energycalculator/MainActivity.java
+++ b/app/src/main/java/me/jj97181818/ch06_energycalculator/MainActivity.java
@@ -2,12 +2,63 @@ package me.jj97181818.ch06_energycalculator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.EditText;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, AdapterView.OnItemSelectedListener {
+ double[] energyRate = {3.1, 4.4, 13.2, 9.7, 5.1, 3.7};
+ EditText weight, time;
+ TextView total, txvRate;
+ Spinner sports;
-public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
+ //設定初值
+ weight = findViewById(R.id.weight);
+ time = findViewById(R.id.timeSpan);
+ total = findViewById(R.id.total);
+ txvRate = findViewById(R.id.txvRate);
+ sports = findViewById(R.id.sports);
+
+ //註冊監聽器
+ sports.setOnItemSelectedListener(this);
+ }
+
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+
+ }
+
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
+ txvRate.setText(String.valueOf(energyRate[position]));
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> parent) {
+
+ }
+
+ public void calc(View v) {
+ String w = weight.getText().toString();
+ String t = time.getText().toString();
+ if (w.isEmpty() || w.equals(".") || t.isEmpty() || t.equals(".")) {
+ total.setText("請輸入體重及運動時間");
+ return;
+ }
+
+ int pos = sports.getSelectedItemPosition();
+
+ long kcal = Math.round(energyRate[pos] * Double.parseDouble(w) * Double.parseDouble(t));
+
+ total.setText(String.format("消耗能量 %d 仟卡", kcal));
}
}