teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

画像の挿入とコードの追加

2021/02/13 02:47

投稿

yasuun
yasuun

スコア7

title CHANGED
File without changes
body CHANGED
@@ -66,6 +66,184 @@
66
66
  }
67
67
 
68
68
  }
69
+
70
+ val weight = editWeight.text.toString().toFloatOrNull()
71
+ val age = editAge.text.toString().toFloatOrNull()
72
+ val hight = editHight.text.toString().toFloatOrNull()
73
+
74
+ //3つの内どれかがnullであればダイアログを表示させる処理
75
+ if (weight == null || age == null || hight == null) {
76
+ AlertDialog.Builder(this)
77
+ .setTitle(R.string.dialog_title_invalid_input).setPositiveButton(android.R.string.ok, null).show()
78
+ return
79
+ }
80
+
81
+
82
+ val data: SharedPreferences = getSharedPreferences("DATA", Context.MODE_PRIVATE)
83
+ val editor = data.edit()
84
+ editor.putFloat("WEIGHT", weight)
85
+ editor.putFloat("AGE", age)
86
+ editor.putFloat("HIGHT", hight)
87
+ editor.apply()
88
+
89
+ startActivity(Intent(this, ResultActivity1::class.java).apply {
90
+ putExtra("WEIGHT", weight)
91
+ putExtra("AGE", age)
92
+ putExtra("HIGHT", hight)
93
+ })
94
+
95
+ }
96
+ }
97
+
98
+ 【activityMain.xml】
99
+ <TextView
100
+ android:id="@+id/welcomDA"
101
+ android:textSize="30sp"
102
+ android:layout_width="wrap_content"
103
+ android:layout_height="wrap_content"
104
+ android:text="WelcomDietAdviser"
105
+ app:layout_constraintBottom_toBottomOf="parent"
106
+ app:layout_constraintEnd_toEndOf="parent"
107
+ app:layout_constraintStart_toStartOf="parent"
108
+ app:layout_constraintTop_toTopOf="parent"
109
+ app:layout_constraintVertical_bias="0.060000002" />
110
+
111
+ <TextView
112
+ android:id="@+id/textView2"
113
+ android:layout_width="wrap_content"
114
+ android:layout_height="wrap_content"
115
+ android:text="まずは基礎代謝を計算しましょう!"
116
+ android:textAppearance="@style/TextAppearance.AppCompat.Large"
117
+ app:layout_constraintBottom_toBottomOf="parent"
118
+ app:layout_constraintEnd_toEndOf="parent"
119
+ app:layout_constraintStart_toStartOf="parent"
120
+ app:layout_constraintTop_toBottomOf="@+id/welcomDA"
121
+ app:layout_constraintVertical_bias="0.07999998" />
122
+
123
+ <EditText
124
+ android:id="@+id/weight"
125
+ android:textSize="20sp"
126
+ android:layout_width="70dp"
127
+ android:layout_height="wrap_content"
128
+ android:ems="10"
129
+ android:hint="50kg"
130
+ android:inputType="numberDecimal"
131
+ app:layout_constraintBottom_toBottomOf="parent"
132
+ app:layout_constraintEnd_toEndOf="parent"
133
+ app:layout_constraintStart_toStartOf="parent"
134
+ app:layout_constraintTop_toBottomOf="@+id/textView2"
135
+ app:layout_constraintVertical_bias="0.120000005" />
136
+
137
+ <EditText
138
+ android:id="@+id/age"
139
+ android:layout_width="70dp"
140
+ android:layout_height="wrap_content"
141
+ android:ems="10"
142
+ android:hint="30歳"
143
+ android:inputType="numberDecimal"
144
+ app:layout_constraintBottom_toBottomOf="parent"
145
+ app:layout_constraintEnd_toEndOf="parent"
146
+ app:layout_constraintStart_toStartOf="parent"
147
+ app:layout_constraintTop_toBottomOf="@+id/weight"
148
+ app:layout_constraintVertical_bias="0.120000005" />
149
+
150
+ <EditText
151
+ android:id="@+id/hight"
152
+ android:layout_width="70dp"
153
+ android:layout_height="wrap_content"
154
+ android:ems="10"
155
+ android:hint="170cm"
156
+ android:inputType="numberDecimal"
157
+ app:layout_constraintBottom_toBottomOf="parent"
158
+ app:layout_constraintEnd_toEndOf="parent"
159
+ app:layout_constraintStart_toStartOf="parent"
160
+ app:layout_constraintTop_toBottomOf="@+id/age"
161
+ app:layout_constraintVertical_bias="0.120000005" />
162
+
163
+ <TextView
164
+ android:id="@+id/kisotaisya"
165
+ android:textSize="30sp"
166
+ android:layout_width="wrap_content"
167
+ android:layout_height="wrap_content"
168
+ android:text="基礎代謝量"
169
+ app:layout_constraintBottom_toBottomOf="parent"
170
+ app:layout_constraintEnd_toEndOf="parent"
171
+ app:layout_constraintStart_toStartOf="parent"
172
+ app:layout_constraintTop_toBottomOf="@+id/hight"
173
+ app:layout_constraintVertical_bias="0.29000002" />
174
+
175
+ <Button
176
+ android:id="@+id/nextBtn"
177
+ android:layout_width="wrap_content"
178
+ android:layout_height="wrap_content"
179
+ android:background="@color/black"
180
+ android:text="NEXT"
181
+ android:textColor="@color/white"
182
+ app:layout_constraintBottom_toBottomOf="parent"
183
+ app:layout_constraintEnd_toEndOf="parent"
184
+ app:layout_constraintHorizontal_bias="0.77"
185
+ app:layout_constraintStart_toStartOf="parent"
186
+ app:layout_constraintTop_toBottomOf="@+id/kisotaisya"
187
+ app:layout_constraintVertical_bias="0.8" />
188
+
189
+ <RadioGroup
190
+ android:id="@+id/radioGroup"
191
+ android:orientation="horizontal"
192
+ android:layout_width="wrap_content"
193
+ android:layout_height="wrap_content"
194
+ app:layout_constraintBottom_toTopOf="@+id/kisotaisya"
195
+ app:layout_constraintEnd_toEndOf="parent"
196
+ app:layout_constraintStart_toStartOf="parent"
197
+ app:layout_constraintTop_toBottomOf="@+id/hight">
198
+
199
+ <RadioButton
200
+ android:id="@+id/man"
201
+ android:layout_width="wrap_content"
202
+ android:layout_height="wrap_content"
203
+ android:text="男"
204
+ android:onClick="onClickCalcButton"
205
+ app:layout_constraintBottom_toTopOf="@+id/kisotaisya"
206
+ app:layout_constraintEnd_toEndOf="parent"
207
+ app:layout_constraintHorizontal_bias="0.37"
208
+ app:layout_constraintStart_toStartOf="parent"
209
+ app:layout_constraintTop_toBottomOf="@+id/hight" />
210
+
211
+ <RadioButton
212
+ android:id="@+id/woman"
213
+ android:layout_width="wrap_content"
214
+ android:layout_height="wrap_content"
215
+ android:text="女"
216
+ android:onClick="onClickCalcButton"
217
+ app:layout_constraintBottom_toBottomOf="@+id/man"
218
+ app:layout_constraintEnd_toEndOf="parent"
219
+ app:layout_constraintHorizontal_bias="0.65"
220
+ app:layout_constraintStart_toStartOf="parent" />
221
+
222
+ </RadioGroup>
223
+
224
+
225
+ <Button
226
+ android:id="@+id/infoBtn"
227
+ android:layout_width="wrap_content"
228
+ android:layout_height="wrap_content"
229
+ android:text="情報を記録する"
230
+ app:layout_constraintBottom_toTopOf="@+id/nextBtn"
231
+ app:layout_constraintEnd_toEndOf="parent"
232
+ app:layout_constraintStart_toStartOf="parent"
233
+ app:layout_constraintTop_toBottomOf="@+id/kisotaisya" />
234
+
235
+ <Button
236
+ android:id="@+id/keisanButton"
237
+ android:layout_width="wrap_content"
238
+ android:layout_height="wrap_content"
239
+ android:text="計算する"
240
+ app:layout_constraintBottom_toBottomOf="parent"
241
+ app:layout_constraintEnd_toStartOf="@+id/nextBtn"
242
+ app:layout_constraintStart_toStartOf="parent"
243
+ app:layout_constraintTop_toBottomOf="@+id/kisotaisya"
244
+ app:layout_constraintVertical_bias="0.79" />›4
245
+
246
+ ![イメージ説明](3340ff6cea762c3d4269dcb2c1ea937f.png)
69
247
  ```
70
248
 
71
249
  ### 試したこと

1

補足文を追加した

2021/02/13 02:47

投稿

yasuun
yasuun

スコア7

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,6 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
- RadioButton男、RadioButton女、どちらか選択したときに男、女でそれぞれ異なる計算処理を戻したい。
3
+ RadioButton男、RadioButton女、どちらか選択し男、女でそれぞれ異なる計算処理を戻したい。
4
-
5
4
  ### 発生している問題・エラーメッセージ
6
5
 
7
6
  ```
@@ -86,4 +85,6 @@
86
85
  初心者で就活用のポートフォリオを作成していて、何時間考えてもわからずお力をお借りしたいです。。。
87
86
  助長な文で申し訳ございません。
88
87
 
88
+ またラジオボタンの選択処理と、男女別で計算を行う処理を分けた方がいいというアドバイスを頂き、何回も試しましたがどのようにすればいいかわかりませんでした。。
89
+
89
90
  ここにより詳細な情報を記載してください。