# AN25 課題No.03 ###### tags: `課題` BMI = 体重(kg) ÷(身長(m) * 身長(m)) BMIの判定基準 18.5未満 やせている 18.5以上~25.0未満 標準 25.0以上 太っている 身長を入力してください(cm) TextView 170.5 EditText 体重を入力してください(kg) TextView 50.2 EditText BMI計算 Button 18.765 TextView 標準です TextView ```xml= //activity_main.xml text="@string/xxxxx" ``` ```xml= //strings.xml <string name="xxxxx">こんにちは</string> ``` mainのtextviewの中身は直接打ち込むのではなくて、strings.xmlの中に用意してそれを呼び出す形で利用する ```xml= //activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/text1" /> <EditText android:id="@+id/edit_height" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="30dp" android:inputType="numberDecimal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/text2" /> <EditText android:id="@+id/edit_weight" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="30dp" android:inputType="numberDecimal" /> <Button android:id="@+id/button_calc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/text3" android:onClick="buttonMethod" /> <TextView android:id="@+id/result_value" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="30dp" android:textSize="30sp" android:textColor="#ff0000" /> <TextView android:id="@+id/result_judge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="30dp" android:textSize="30sp" android:textColor="#ff0000" /> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="right" /> </LinearLayout> ``` ```xml= //strings.xml <resources> <string name="app_name">MyBMI</string> <string name="action_settings">MyBMI</string> <string name="text1">身長を入力してください(cm)</string> <string name="text2">体重を入力してください(kg)</string> <string name="text3">BMI値を計算</string> <string name="result_judge_0">やせています</string> <string name="result_judge_1">標準です</string> <string name="result_judge_2">太っています</string> </resources> ``` ```java= //MainActivity.java package nhs00650.hal.ac.mybmi; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.os.Bundle; import android.view.View; import android.widget.TextView; import android.widget.EditText; public class MainActivity extends AppCompatActivity { private EditText heightEditText; private EditText weightEditText; private TextView resultTextView; private TextView judgeTextView; float heightint; float weightint; float bmiint; String bmistr; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); heightEditText = (EditText)findViewById(R.id.edit_height); weightEditText = (EditText)findViewById(R.id.edit_weight); resultTextView = (TextView)findViewById(R.id.result_value); judgeTextView = (TextView)findViewById(R.id.result_judge); } public void buttonMethod(View btn_calc) { heightint = Float.parseFloat(heightEditText.getText().toString()); weightint = Float.parseFloat(weightEditText.getText().toString()); bmiMethod(); } public void bmiMethod() { heightint = heightint / 100; float heightintdub = heightint * heightint; bmiint = weightint / heightintdub; //小数点以下5桁で切っている bmistr = String.format("%.5f",bmiint); resultTextView.setText(bmistr); if(bmiint < 18.5){ judgeTextView.setText(R.string.result_judge_0); }else if(bmiint < 25.0) { judgeTextView.setText(R.string.result_judge_1); }else{ judgeTextView.setText(R.string.result_judge_2); } } } ``` <span style="color: #ff3333">aaa</span> <span style="text-decoration: underline">aaa</span> ## 雑談 (0→やまぴ 1→みや 2→やすい 3→りょうくん 4→アミカ) 3.採用あるある川柳 おもしろい https://news.yahoo.co.jp/articles/a2744331545ec36a956e891278ac0855fbf9e4bb 1.川柳作って 3.急に難しい話を…… 3.マスクして 増える美人 減る出会い :heart: 1.うまいけども笑 3.宮も作ってや 1.リモート用 そこだけ整頓 部屋のすみ 3.朝起きて ジャケット着れば もうオフィス :office: あるけど 何の'?'zozodeiiyann amazonは?yahooとか楽天とか? 当たってみろ 2.zozotown以外でバック wないんかぁ 公式サイトか 全部あたってみる ^-^ 公式サイトで買えば? 吉田カバンとかええよ
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up