# AN25 課題No.04 ###### tags: `課題` ```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" /> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="right" /> </LinearLayout> ``` ```xml= //result.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:layout_marginBottom="30dip" android:text="@string/result_msg" /> <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" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="30dip" android:text="@string/good_msg" /> <TextView android:id="@+id/good_weight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="30dp" android:textSize="30sp" android:textColor="#ff0000" /> <Button android:text="@string/btn_reset" android:id="@+id/button_reset" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="buttonMethod" /> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="right" /> </LinearLayout> ``` ```xml= //string.xml <resources> <string name="app_name">MyBMI</string> <string name="sub_name">Result</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> <string name="result_msg">あなたのBMI値は...</string> <string name="good_msg">標準体重まで</string> <string name="btn_reset">リセット</string> </resources> ``` ```java= //MainActivty.java package nhs00650.hal.ac.mybmi; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.content.Intent; import android.view.View; import android.widget.TextView; import android.widget.EditText; public class MainActivity extends AppCompatActivity { private EditText heightEditText; private EditText weightEditText; float heightint; float weightint; float bmiint; String bmistr; float waweight; float rweight; String rweightStr; @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); } public void buttonMethod(View btn_calc) { heightint = Float.parseFloat(heightEditText.getText().toString()); weightint = Float.parseFloat(weightEditText.getText().toString()); bmiMethod(); Intent result_act = new Intent(MainActivity.this, Result.class); result_act.putExtra("BMI", bmiint); result_act.putExtra("GOODWEIGHT", rweight); startActivity(result_act); } public void bmiMethod() { heightint = heightint / 100; float heightintdub = heightint * heightint; bmiint = weightint / heightintdub; bmistr = String.format("%.5f",bmiint); waweight = heightint * heightint * 22; rweight = waweight - weightint; rweightStr = String.format("%.5f",rweight); } } ``` ```java= //result.java package nhs00650.hal.ac.mybmi; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.content.Intent; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity; import org.w3c.dom.Text; public class Result extends AppCompatActivity { private TextView resultTextView; private TextView judgeTextView; private TextView goodTextView; float bmiint; String bmistr; float goodint; String goodStr; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.result); resultTextView = (TextView)findViewById(R.id.result_value); judgeTextView = (TextView)findViewById(R.id.result_judge); goodTextView = (TextView)findViewById(R.id.good_weight); Bundle extras = getIntent().getExtras(); if(extras != null){ bmiint = extras.getFloat("BMI"); goodint = extras.getFloat("GOODWEIGHT"); peroperoMethod(); } } public void peroperoMethod() { 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); } bmistr = String.format("%.5f",bmiint); resultTextView.setText(bmistr); goodStr = String.format("%.5f",goodint); goodTextView.setText(goodStr); } public void buttonMethod(View btn_reset){ Intent reset_act = new Intent(Result.this, MainActivity.class); startActivity(reset_act); } } ``` ```xml= //Android.manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="nhs00650.hal.ac.mybmi"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Result" android:label="@string/sub_name"> </activity> </application> </manifest> ``` ## 雑談 (0→やまぴ 1→みや 2→やすい 3→りょうくん 4→アミカ 5→やの) --- <span style="color: #ff3333">aaa</span> <span style="text-decoration: underline">aaa</span>
×
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