質問編集履歴

4

コード追加

2019/11/20 03:36

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -78,13 +78,51 @@
78
78
 
79
79
 
80
80
 
81
+ public class MainFragment extends Fragment {
82
+
83
+
84
+
85
+ public static final String Gtai12 = "person_id";
86
+
87
+ //public static final String EXTRA_MODE_ID = "mode_id";
88
+
89
+
90
+
91
+
92
+
93
+ fragment2 fragment02 = new fragment2();
94
+
95
+
96
+
97
+
98
+
99
+ private MainViewModel mViewModel;
100
+
101
+
102
+
81
- public static MainFragment newInstance() {
103
+ public static MainFragment newInstance() {
82
104
 
83
105
  return new MainFragment();
84
106
 
85
107
  }
86
108
 
109
+
110
+
111
+ @Nullable
112
+
87
- @Override
113
+ @Override
114
+
115
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
116
+
117
+ @Nullable Bundle savedInstanceState) {
118
+
119
+ return inflater.inflate(R.layout.main_fragment, container, false);
120
+
121
+ }
122
+
123
+
124
+
125
+ @Override
88
126
 
89
127
  public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
90
128
 
@@ -92,6 +130,10 @@
92
130
 
93
131
 
94
132
 
133
+
134
+
135
+
136
+
95
137
  Bundle args = getArguments();
96
138
 
97
139
 
@@ -134,24 +176,28 @@
134
176
 
135
177
  });
136
178
 
179
+ }
180
+
181
+
182
+
183
+ @Override
184
+
185
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
186
+
187
+ super.onActivityCreated(savedInstanceState);
188
+
189
+ mViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
190
+
191
+ // TODO: Use the ViewModel
192
+
193
+ }
194
+
195
+
196
+
137
197
  }
138
198
 
139
199
 
140
200
 
141
- @Override
142
-
143
- public void onActivityCreated(@Nullable Bundle savedInstanceState) {
144
-
145
- super.onActivityCreated(savedInstanceState);
146
-
147
- mViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
148
-
149
- // TODO: Use the ViewModel
150
-
151
- }
152
-
153
-
154
-
155
201
  ```
156
202
 
157
203
 
@@ -162,10 +208,48 @@
162
208
 
163
209
  ```java
164
210
 
211
+
212
+
165
213
  public class fragment2 extends Fragment {
166
214
 
167
215
 
168
216
 
217
+ private int cnt = 0;
218
+
219
+
220
+
221
+ private String gtai;
222
+
223
+ //入力されたやつを数値に変えた体重
224
+
225
+ private double tai;
226
+
227
+ private double bmi;
228
+
229
+
230
+
231
+ private String s;
232
+
233
+
234
+
235
+ double shin = 150.2;
236
+
237
+ //double tai = 50.8;
238
+
239
+ double mtai = 58.0;
240
+
241
+
242
+
243
+ Calendar cal = Calendar.getInstance();
244
+
245
+ int month = cal.get(Calendar.MONTH) + 1;
246
+
247
+
248
+
249
+ double shinm = shin / 100;
250
+
251
+ double shinm2 = shinm * shinm;
252
+
169
253
 
170
254
 
171
255
  public static fragment2 newInstance(int count) {
@@ -192,7 +276,7 @@
192
276
 
193
277
 
194
278
 
195
- // FragmentのViewを生成して返す
279
+ // FragmentのViewを生成して返す
196
280
 
197
281
  @Override
198
282
 
@@ -200,9 +284,9 @@
200
284
 
201
285
  ViewGroup container,
202
286
 
203
- Bundle savedInstanceState){
287
+ Bundle savedInstanceState) {
204
-
288
+
205
- View wf = inflater.inflate(R.layout.fragment, container, false);
289
+ View wf = inflater.inflate(R.layout.fragment, container, false);
206
290
 
207
291
 
208
292
 
@@ -224,7 +308,7 @@
224
308
 
225
309
 
226
310
 
227
- @Override
311
+ @Override
228
312
 
229
313
  public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
230
314
 
@@ -234,23 +318,125 @@
234
318
 
235
319
  final TextView reserve_2c_text = getActivity().findViewById(R.id.textView);
236
320
 
321
+ // R.id.textviewはフラグメント1内の書き込みたいセルのid
322
+
323
+ //fragment.xml には textview はつけてない
324
+
325
+
326
+
237
- Bundle args = getArguments();
327
+ Bundle args = getArguments();
328
+
329
+
330
+
238
-
331
+ /*@Override
332
+
239
-
333
+ public void onStart() {
334
+
240
-
335
+ super.onStart();*/
336
+
241
- Button bu1 = (Button) getActivity().findViewById(R.id.button2);
337
+ Button bu1 = (Button) getActivity().findViewById(R.id.button2);
338
+
339
+
242
340
 
243
341
  bu1.setOnClickListener(new View.OnClickListener(){
244
342
 
343
+ @Override
344
+
345
+ public void onClick(View view){
346
+
245
- EditText ked = (EditText) getActivity().findViewById(R.id.editText);
347
+ EditText ked = (EditText) getActivity().findViewById(R.id.editText);
348
+
246
-
349
+ EditText mted = (EditText) getActivity().findViewById(R.id.editText2);
350
+
351
+ EditText ted = (EditText) getActivity().findViewById(R.id.editText3);
352
+
353
+
354
+
355
+ //今は月単位の指定しかできない
356
+
357
+ //入力値を文字列から数値へ 数値から文字列へして表示
358
+
359
+ String kikan = ked.getText().toString();
360
+
361
+ String mtai = mted.getText().toString();
362
+
247
- @Override
363
+ gtai = ted.getText().toString();
364
+
248
-
365
+ Toast.makeText(getActivity(), "click", Toast.LENGTH_SHORT).show();
366
+
249
- public void onClick(View view){
367
+ if (kikan.length() != 0) {
368
+
250
-
369
+ int i = Integer.parseInt(kikan);
370
+
251
-
371
+ int mki = month + i;
372
+
252
-
373
+ if (mki > 12) {
374
+
375
+ mki -= 12;
376
+
377
+ }
378
+
379
+ s = String.valueOf(mki);
380
+
381
+ ked.getEditableText().clear();
382
+
383
+ }else{
384
+
385
+
386
+
387
+ }
388
+
389
+
390
+
391
+ if (mtai.length() != 0) {
392
+
393
+ mted.getEditableText().clear();
394
+
395
+
396
+
397
+ }
398
+
399
+
400
+
401
+ if(gtai.length() != 0){
402
+
403
+ tai = Double.parseDouble(gtai);
404
+
405
+ bmi = tai / shinm2;
406
+
407
+ ted.getEditableText().clear();
408
+
409
+ }
410
+
411
+
412
+
413
+ // ここでフラグメント1にあるテーブル内のセルに値を書き込んでいる
414
+
253
- reserve_2c_text.setText("");
415
+ reserve_2c_text.setText("現在の体重" + gtai);
416
+
417
+ }
418
+
419
+ });
420
+
421
+ }
422
+
423
+ /*
424
+
425
+ private void showPerson(String personId) {
426
+
427
+ Intent intent = new Intent(fragment2.this,MainFragment.);
428
+
429
+ intent.putExtra(MainFragment.Gtai12, personId);
430
+
431
+ // intent.putExtra(PersonActivity.EXTRA_MODE_ID, MODE_PRIVACY);
432
+
433
+ // ^^^if needed^^^
434
+
435
+ startActivity(intent);
436
+
437
+ }*/
438
+
439
+ }
254
440
 
255
441
 
256
442
 

3

文章の変更

2019/11/20 03:36

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -76,9 +76,19 @@
76
76
 
77
77
  ```java
78
78
 
79
+
80
+
81
+ public static MainFragment newInstance() {
82
+
83
+ return new MainFragment();
84
+
85
+ }
86
+
79
87
  @Override
80
88
 
81
- public void onViewCreated(~~
89
+ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
90
+
91
+ super.onViewCreated(view, savedInstanceState);
82
92
 
83
93
 
84
94
 
@@ -124,6 +134,22 @@
124
134
 
125
135
  });
126
136
 
137
+ }
138
+
139
+
140
+
141
+ @Override
142
+
143
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
144
+
145
+ super.onActivityCreated(savedInstanceState);
146
+
147
+ mViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
148
+
149
+ // TODO: Use the ViewModel
150
+
151
+ }
152
+
127
153
 
128
154
 
129
155
  ```
@@ -170,7 +196,13 @@
170
196
 
171
197
  @Override
172
198
 
173
- public View onCreateView(~~~~
199
+ public View onCreateView(@NonNull LayoutInflater inflater,
200
+
201
+ ViewGroup container,
202
+
203
+ Bundle savedInstanceState){
204
+
205
+ View wf = inflater.inflate(R.layout.fragment, container, false);
174
206
 
175
207
 
176
208
 
@@ -194,7 +226,9 @@
194
226
 
195
227
  @Override
196
228
 
197
- public void onViewCreated(~~~
229
+ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
230
+
231
+ super.onViewCreated(view, savedInstanceState);
198
232
 
199
233
 
200
234
 
@@ -252,4 +286,6 @@
252
286
 
253
287
 
254
288
 
255
- ここにより詳細な情報を記載してください。
289
+ android studio Version 3.5
290
+
291
+ 選んだものは Fragment + ViewModel かと思います

2

文章の変更

2019/11/20 03:11

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -72,14 +72,10 @@
72
72
 
73
73
 
74
74
 
75
+ fragment1.java
76
+
75
77
  ```java
76
78
 
77
- fragment1.java
78
-
79
- ```
80
-
81
-
82
-
83
79
  @Override
84
80
 
85
81
  public void onViewCreated(~~
@@ -130,18 +126,16 @@
130
126
 
131
127
 
132
128
 
133
-
129
+ ```
130
+
131
+
132
+
133
+ fragment2.java
134
134
 
135
135
 
136
136
 
137
137
  ```java
138
138
 
139
- fragment2.java
140
-
141
- ```
142
-
143
-
144
-
145
139
  public class fragment2 extends Fragment {
146
140
 
147
141
 
@@ -224,7 +218,9 @@
224
218
 
225
219
  reserve_2c_text.setText("");
226
220
 
221
+
222
+
227
- ~~~~
223
+ ```
228
224
 
229
225
 
230
226
 

1

文章の編集

2019/11/20 02:56

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -72,18 +72,12 @@
72
72
 
73
73
 
74
74
 
75
- ```ここに言語名を入力
76
-
77
- java
75
+ ```java
78
-
79
- ```
80
-
81
-
82
-
83
-
84
76
 
85
77
  fragment1.java
86
78
 
79
+ ```
80
+
87
81
 
88
82
 
89
83
  @Override
@@ -140,8 +134,12 @@
140
134
 
141
135
 
142
136
 
137
+ ```java
138
+
143
139
  fragment2.java
144
140
 
141
+ ```
142
+
145
143
 
146
144
 
147
145
  public class fragment2 extends Fragment {