質問編集履歴

3

追記

2020/06/27 01:47

投稿

yukari00
yukari00

スコア5

test CHANGED
File without changes
test CHANGED
@@ -28,8 +28,82 @@
28
28
 
29
29
 
30
30
 
31
+ ↑さらに追記です。
32
+
33
+ ログを使ってさらに調べたところ、
34
+
35
+ FirebaseのaddSnapshotListener(リアルタイムでデータ取得するメソッド)を出力した後に、テキストビューがnullになっているということが判明しました。ますます意味がわかりません。なぜ、途中でテキストビューがnullになってしまうのでしょう??
36
+
37
+
38
+
31
39
  ```ここに言語を入力
32
40
 
41
+ private fun getTwoTeamInfoFromFirestore() {
42
+
43
+
44
+
45
+ Log.d("text1", "$text_tell_which_team")//これはnullではない
46
+
47
+ listeningMembers = database.collection(dbCollection).document(keyword).collection("members")
48
+
49
+ .addSnapshotListener { it, e ->
50
+
51
+ val membersListUpdate: MutableList<Uid> = mutableListOf()
52
+
53
+ val teamRed: MutableList<Uid> = mutableListOf()
54
+
55
+ val teamBlue: MutableList<Uid> = mutableListOf()
56
+
57
+
58
+
59
+ Log.d("!!!!!!!!!!!!", "!!!!!!!!!!!!!!")
60
+
61
+
62
+
63
+ if(e != null) return@addSnapshotListener
64
+
65
+ if(it == null || it.isEmpty) return@addSnapshotListener
66
+
67
+ for (document in it) {
68
+
69
+ val name = document.getString("name")?: ""
70
+
71
+ val uid = document.id
72
+
73
+ val team = document.getString("team")
74
+
75
+ membersListUpdate.add(Uid(name, uid))
76
+
77
+ if(team == "RED") teamRed.add(Uid(name, uid)) else teamBlue.add(Uid(name, uid))
78
+
79
+ }
80
+
81
+
82
+
83
+ Log.d("text2", "$text_tell_which_team")//null
84
+
85
+ membersList = membersListUpdate
86
+
87
+
88
+
89
+ if(teamRed.size != 0) {
90
+
91
+ setSpinner(teamRed, teamBlue)
92
+
93
+ individualsInfo(teamRed, teamBlue)
94
+
95
+ }
96
+
97
+ }
98
+
99
+ }
100
+
101
+ ```
102
+
103
+
104
+
105
+ ```ここに言語を入力
106
+
33
107
  override fun onCreateView(
34
108
 
35
109
  inflater: LayoutInflater, container: ViewGroup?,
@@ -50,424 +124,352 @@
50
124
 
51
125
  ```ここに言語を入力
52
126
 
53
- private fun individualsInfo(
54
-
55
- teamRed: MutableList<Uid>,
56
-
57
- teamBlue: MutableList<Uid>
58
-
59
- ) {
60
-
61
-
62
-
63
- val teamRedNameList = mutableListOf<String>()
64
-
65
- val teamBlueNameList = mutableListOf<String>()
66
-
67
- teamRed.forEach {
68
-
69
- teamRedNameList.add(it.name)
70
-
71
- }
72
-
73
- teamBlue.forEach {
74
-
75
- teamBlueNameList.add(it.name)
76
-
77
- }
78
-
79
-
80
-
81
- val myTeam = if (teamRedNameList.contains(nickname)) "RED" else "BLUE"
82
-
83
-
84
-
85
- Log.d("nickname", "$nickname")
86
-
87
-
88
-
89
- if (myTeam == "RED") {
90
-
91
- text_tell_which_team.text = "${nickname}さん、あなたは赤チームです"
92
-
93
- text_my_team_members.text = teamRedNameList.joinToString()
94
-
95
- } else {
96
-
97
- text_tell_which_team.text = "${nickname}さん、あなたは青チームです"
98
-
99
- text_my_team_members.text = teamBlueNameList.joinToString()
100
-
101
- }
102
-
103
-
104
-
105
- text_red_mem_num.text = "赤チムの人数は${teamRedNameList.size}人です"
106
-
107
- text_blue_mem_num.text = "青チームの人数は${teamBlueNameList.size}人です"
108
-
109
-
110
-
111
- showHost(myTeam)
112
-
113
- }
114
-
115
-
127
+ <?xml version="1.0" encoding="utf-8"?>
128
+
129
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
130
+
131
+ xmlns:app="http://schemas.android.com/apk/res-auto"
132
+
133
+ xmlns:tools="http://schemas.android.com/tools"
134
+
135
+ android:layout_width="match_parent"
136
+
137
+ android:layout_height="match_parent"
138
+
139
+ android:background="@drawable/shape_round_corners"
140
+
141
+ tools:context=".GameSettingFragment">
142
+
143
+
144
+
145
+ <TextView
146
+
147
+ android:id="@+id/text_tell_which_team"
148
+
149
+ android:layout_width="match_parent"
150
+
151
+ android:layout_height="wrap_content"
152
+
153
+ android:layout_marginTop="16dp"
154
+
155
+ android:text="あなたは赤チームです"
156
+
157
+ android:textColor="@color/WHITE"
158
+
159
+ android:gravity="center"
160
+
161
+ app:layout_constraintStart_toStartOf="parent"
162
+
163
+ app:layout_constraintEnd_toEndOf="parent"
164
+
165
+ app:layout_constraintTop_toBottomOf="@id/text_blue_mem_num" />
166
+
167
+
168
+
169
+ <TextView
170
+
171
+ android:id="@+id/text_if_leader"
172
+
173
+ android:layout_width="match_parent"
174
+
175
+ android:layout_height="wrap_content"
176
+
177
+ android:layout_marginTop="8dp"
178
+
179
+ android:text="あなたはスパイマスターです"
180
+
181
+ android:textColor="@color/WHITE"
182
+
183
+ android:gravity="center"
184
+
185
+ app:layout_constraintStart_toStartOf="parent"
186
+
187
+ app:layout_constraintEnd_toEndOf="parent"
188
+
189
+ app:layout_constraintTop_toBottomOf="@id/text_tell_which_team" />
190
+
191
+
192
+
193
+
194
+
195
+ <LinearLayout
196
+
197
+ android:id="@+id/linear"
198
+
199
+ android:layout_width="match_parent"
200
+
201
+ android:layout_height="0dp"
202
+
203
+ android:layout_marginStart="16dp"
204
+
205
+ android:layout_marginTop="16dp"
206
+
207
+ android:layout_marginEnd="16dp"
208
+
209
+ android:orientation="vertical"
210
+
211
+ app:layout_constraintBottom_toTopOf="@+id/linearLayout"
212
+
213
+ app:layout_constraintEnd_toEndOf="parent"
214
+
215
+ app:layout_constraintHorizontal_bias="0.0"
216
+
217
+ app:layout_constraintStart_toStartOf="parent"
218
+
219
+ app:layout_constraintTop_toBottomOf="@id/text_if_leader"
220
+
221
+ app:layout_constraintVertical_bias="0.0">
222
+
223
+
224
+
225
+ <TextView
226
+
227
+ android:layout_width="match_parent"
228
+
229
+ android:layout_height="wrap_content"
230
+
231
+ android:text="あなたの仲間は..."
232
+
233
+ android:textColor="@color/WHITE"
234
+
235
+ android:gravity="center"/>
236
+
237
+
238
+
239
+ <TextView
240
+
241
+ android:id="@+id/text_my_team_members"
242
+
243
+ android:layout_width="match_parent"
244
+
245
+ android:layout_height="match_parent"
246
+
247
+ android:textColor="@color/WHITE"
248
+
249
+ android:gravity="center"/>
250
+
251
+ </LinearLayout>
252
+
253
+
254
+
255
+ <LinearLayout
256
+
257
+ android:id="@+id/linearLayout"
258
+
259
+ android:layout_width="400dp"
260
+
261
+ android:layout_height="wrap_content"
262
+
263
+ android:layout_margin="16dp"
264
+
265
+ android:orientation="horizontal"
266
+
267
+ app:layout_constraintBottom_toTopOf="@+id/liner_btn"
268
+
269
+ app:layout_constraintEnd_toEndOf="parent"
270
+
271
+ app:layout_constraintStart_toStartOf="parent"
272
+
273
+ app:layout_constraintTop_toBottomOf="@id/linear" >
274
+
275
+
276
+
277
+ <TextView
278
+
279
+ android:id="@+id/textView2"
280
+
281
+ android:layout_width="0dp"
282
+
283
+ android:layout_height="match_parent"
284
+
285
+ android:layout_weight="4"
286
+
287
+ android:gravity="center"
288
+
289
+ android:text="スパイマスターを変更しますか"
290
+
291
+ android:textColor="@color/WHITE"/>
292
+
293
+
294
+
295
+ <Spinner
296
+
297
+ android:id="@+id/spinner"
298
+
299
+ android:layout_width="0dp"
300
+
301
+ android:layout_height="match_parent"
302
+
303
+ android:layout_weight="3" />
304
+
305
+
306
+
307
+ <Button
308
+
309
+ android:id="@+id/btn_change_leader"
310
+
311
+ android:layout_width="0dp"
312
+
313
+ android:layout_height="wrap_content"
314
+
315
+ android:layout_weight="1"
316
+
317
+ android:background="@drawable/ic_baseline_cached_24"/>
318
+
319
+
320
+
321
+ </LinearLayout>
322
+
323
+
324
+
325
+ <Button
326
+
327
+ android:id="@+id/btn_leave_room"
328
+
329
+ android:layout_width="30dp"
330
+
331
+ android:layout_height="30dp"
332
+
333
+ android:layout_margin="12dp"
334
+
335
+ android:background="@drawable/ic_baseline_arrow_back_24"
336
+
337
+ app:layout_constraintTop_toTopOf="parent"
338
+
339
+ app:layout_constraintStart_toStartOf="parent"/>
340
+
341
+
342
+
343
+ <LinearLayout
344
+
345
+ android:id="@+id/liner_btn"
346
+
347
+ android:layout_width="match_parent"
348
+
349
+ android:layout_height="wrap_content"
350
+
351
+ android:orientation="horizontal"
352
+
353
+ android:layout_margin="12dp"
354
+
355
+ app:layout_constraintBottom_toBottomOf="parent"
356
+
357
+ app:layout_constraintStart_toStartOf="parent"
358
+
359
+ app:layout_constraintEnd_toEndOf="parent">
360
+
361
+
362
+
363
+ <Button
364
+
365
+ android:id="@+id/btn_team_random"
366
+
367
+ android:layout_width="0dp"
368
+
369
+ android:layout_height="30dp"
370
+
371
+ android:layout_marginEnd="6dp"
372
+
373
+ android:layout_weight="1"
374
+
375
+ android:background="@drawable/shape_round_coners_winered"
376
+
377
+ android:text="ランダム"
378
+
379
+ android:textColor="@color/WHITE"
380
+
381
+ app:layout_constraintBottom_toBottomOf="parent"
382
+
383
+ app:layout_constraintStart_toStartOf="parent" />
384
+
385
+
386
+
387
+ <Button
388
+
389
+ android:id="@+id/btn_prepared"
390
+
391
+ android:layout_width="0dp"
392
+
393
+ android:layout_height="30dp"
394
+
395
+ android:layout_weight="1"
396
+
397
+ android:layout_marginStart="6dp"
398
+
399
+ android:background="@drawable/shape_round_coners_winered"
400
+
401
+ android:text="準備完了"
402
+
403
+ android:textColor="@color/WHITE"
404
+
405
+ app:layout_constraintBottom_toBottomOf="parent"
406
+
407
+ app:layout_constraintEnd_toEndOf="parent" />
408
+
409
+
410
+
411
+ </LinearLayout>
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+ <TextView
424
+
425
+ android:id="@+id/text_red_mem_num"
426
+
427
+ android:layout_width="wrap_content"
428
+
429
+ android:layout_height="wrap_content"
430
+
431
+ android:layout_marginTop="16dp"
432
+
433
+ android:layout_marginEnd="16dp"
434
+
435
+ android:text="赤チーム人数"
436
+
437
+ android:textColor="@color/WHITE"
438
+
439
+ android:textSize="12dp"
440
+
441
+ app:layout_constraintEnd_toEndOf="parent"
442
+
443
+ app:layout_constraintTop_toTopOf="parent" />
444
+
445
+
446
+
447
+ <TextView
448
+
449
+ android:id="@+id/text_blue_mem_num"
450
+
451
+ android:layout_width="wrap_content"
452
+
453
+ android:layout_height="wrap_content"
454
+
455
+ android:layout_marginTop="8dp"
456
+
457
+ android:layout_marginEnd="16dp"
458
+
459
+ android:text="青チーム人数"
460
+
461
+ android:textColor="@color/WHITE"
462
+
463
+ android:textSize="12dp"
464
+
465
+ app:layout_constraintEnd_toEndOf="parent"
466
+
467
+ app:layout_constraintTop_toBottomOf="@id/text_red_mem_num" />
468
+
469
+
470
+
471
+
472
+
473
+ </androidx.constraintlayout.widget.ConstraintLayout>
116
474
 
117
475
  ```
118
-
119
-
120
-
121
-
122
-
123
- ```ここに言語を入力
124
-
125
- <?xml version="1.0" encoding="utf-8"?>
126
-
127
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
128
-
129
- xmlns:app="http://schemas.android.com/apk/res-auto"
130
-
131
- xmlns:tools="http://schemas.android.com/tools"
132
-
133
- android:layout_width="match_parent"
134
-
135
- android:layout_height="match_parent"
136
-
137
- android:background="@drawable/shape_round_corners"
138
-
139
- tools:context=".GameSettingFragment">
140
-
141
-
142
-
143
- <TextView
144
-
145
- android:id="@+id/text_tell_which_team"
146
-
147
- android:layout_width="match_parent"
148
-
149
- android:layout_height="wrap_content"
150
-
151
- android:layout_marginTop="16dp"
152
-
153
- android:text="あなたは赤チームです"
154
-
155
- android:textColor="@color/WHITE"
156
-
157
- android:gravity="center"
158
-
159
- app:layout_constraintStart_toStartOf="parent"
160
-
161
- app:layout_constraintEnd_toEndOf="parent"
162
-
163
- app:layout_constraintTop_toBottomOf="@id/text_blue_mem_num" />
164
-
165
-
166
-
167
- <TextView
168
-
169
- android:id="@+id/text_if_leader"
170
-
171
- android:layout_width="match_parent"
172
-
173
- android:layout_height="wrap_content"
174
-
175
- android:layout_marginTop="8dp"
176
-
177
- android:text="あなたはスパイマスターです"
178
-
179
- android:textColor="@color/WHITE"
180
-
181
- android:gravity="center"
182
-
183
- app:layout_constraintStart_toStartOf="parent"
184
-
185
- app:layout_constraintEnd_toEndOf="parent"
186
-
187
- app:layout_constraintTop_toBottomOf="@id/text_tell_which_team" />
188
-
189
-
190
-
191
-
192
-
193
- <LinearLayout
194
-
195
- android:id="@+id/linear"
196
-
197
- android:layout_width="match_parent"
198
-
199
- android:layout_height="0dp"
200
-
201
- android:layout_marginStart="16dp"
202
-
203
- android:layout_marginTop="16dp"
204
-
205
- android:layout_marginEnd="16dp"
206
-
207
- android:orientation="vertical"
208
-
209
- app:layout_constraintBottom_toTopOf="@+id/linearLayout"
210
-
211
- app:layout_constraintEnd_toEndOf="parent"
212
-
213
- app:layout_constraintHorizontal_bias="0.0"
214
-
215
- app:layout_constraintStart_toStartOf="parent"
216
-
217
- app:layout_constraintTop_toBottomOf="@id/text_if_leader"
218
-
219
- app:layout_constraintVertical_bias="0.0">
220
-
221
-
222
-
223
- <TextView
224
-
225
- android:layout_width="match_parent"
226
-
227
- android:layout_height="wrap_content"
228
-
229
- android:text="あなたの仲間は..."
230
-
231
- android:textColor="@color/WHITE"
232
-
233
- android:gravity="center"/>
234
-
235
-
236
-
237
- <TextView
238
-
239
- android:id="@+id/text_my_team_members"
240
-
241
- android:layout_width="match_parent"
242
-
243
- android:layout_height="match_parent"
244
-
245
- android:textColor="@color/WHITE"
246
-
247
- android:gravity="center"/>
248
-
249
- </LinearLayout>
250
-
251
-
252
-
253
- <LinearLayout
254
-
255
- android:id="@+id/linearLayout"
256
-
257
- android:layout_width="400dp"
258
-
259
- android:layout_height="wrap_content"
260
-
261
- android:layout_margin="16dp"
262
-
263
- android:orientation="horizontal"
264
-
265
- app:layout_constraintBottom_toTopOf="@+id/liner_btn"
266
-
267
- app:layout_constraintEnd_toEndOf="parent"
268
-
269
- app:layout_constraintStart_toStartOf="parent"
270
-
271
- app:layout_constraintTop_toBottomOf="@id/linear" >
272
-
273
-
274
-
275
- <TextView
276
-
277
- android:id="@+id/textView2"
278
-
279
- android:layout_width="0dp"
280
-
281
- android:layout_height="match_parent"
282
-
283
- android:layout_weight="4"
284
-
285
- android:gravity="center"
286
-
287
- android:text="スパイマスターを変更しますか"
288
-
289
- android:textColor="@color/WHITE"/>
290
-
291
-
292
-
293
- <Spinner
294
-
295
- android:id="@+id/spinner"
296
-
297
- android:layout_width="0dp"
298
-
299
- android:layout_height="match_parent"
300
-
301
- android:layout_weight="3" />
302
-
303
-
304
-
305
- <Button
306
-
307
- android:id="@+id/btn_change_leader"
308
-
309
- android:layout_width="0dp"
310
-
311
- android:layout_height="wrap_content"
312
-
313
- android:layout_weight="1"
314
-
315
- android:background="@drawable/ic_baseline_cached_24"/>
316
-
317
-
318
-
319
- </LinearLayout>
320
-
321
-
322
-
323
- <Button
324
-
325
- android:id="@+id/btn_leave_room"
326
-
327
- android:layout_width="30dp"
328
-
329
- android:layout_height="30dp"
330
-
331
- android:layout_margin="12dp"
332
-
333
- android:background="@drawable/ic_baseline_arrow_back_24"
334
-
335
- app:layout_constraintTop_toTopOf="parent"
336
-
337
- app:layout_constraintStart_toStartOf="parent"/>
338
-
339
-
340
-
341
- <LinearLayout
342
-
343
- android:id="@+id/liner_btn"
344
-
345
- android:layout_width="match_parent"
346
-
347
- android:layout_height="wrap_content"
348
-
349
- android:orientation="horizontal"
350
-
351
- android:layout_margin="12dp"
352
-
353
- app:layout_constraintBottom_toBottomOf="parent"
354
-
355
- app:layout_constraintStart_toStartOf="parent"
356
-
357
- app:layout_constraintEnd_toEndOf="parent">
358
-
359
-
360
-
361
- <Button
362
-
363
- android:id="@+id/btn_team_random"
364
-
365
- android:layout_width="0dp"
366
-
367
- android:layout_height="30dp"
368
-
369
- android:layout_marginEnd="6dp"
370
-
371
- android:layout_weight="1"
372
-
373
- android:background="@drawable/shape_round_coners_winered"
374
-
375
- android:text="ランダム"
376
-
377
- android:textColor="@color/WHITE"
378
-
379
- app:layout_constraintBottom_toBottomOf="parent"
380
-
381
- app:layout_constraintStart_toStartOf="parent" />
382
-
383
-
384
-
385
- <Button
386
-
387
- android:id="@+id/btn_prepared"
388
-
389
- android:layout_width="0dp"
390
-
391
- android:layout_height="30dp"
392
-
393
- android:layout_weight="1"
394
-
395
- android:layout_marginStart="6dp"
396
-
397
- android:background="@drawable/shape_round_coners_winered"
398
-
399
- android:text="準備完了"
400
-
401
- android:textColor="@color/WHITE"
402
-
403
- app:layout_constraintBottom_toBottomOf="parent"
404
-
405
- app:layout_constraintEnd_toEndOf="parent" />
406
-
407
-
408
-
409
- </LinearLayout>
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
- <TextView
422
-
423
- android:id="@+id/text_red_mem_num"
424
-
425
- android:layout_width="wrap_content"
426
-
427
- android:layout_height="wrap_content"
428
-
429
- android:layout_marginTop="16dp"
430
-
431
- android:layout_marginEnd="16dp"
432
-
433
- android:text="赤チーム人数"
434
-
435
- android:textColor="@color/WHITE"
436
-
437
- android:textSize="12dp"
438
-
439
- app:layout_constraintEnd_toEndOf="parent"
440
-
441
- app:layout_constraintTop_toTopOf="parent" />
442
-
443
-
444
-
445
- <TextView
446
-
447
- android:id="@+id/text_blue_mem_num"
448
-
449
- android:layout_width="wrap_content"
450
-
451
- android:layout_height="wrap_content"
452
-
453
- android:layout_marginTop="8dp"
454
-
455
- android:layout_marginEnd="16dp"
456
-
457
- android:text="青チーム人数"
458
-
459
- android:textColor="@color/WHITE"
460
-
461
- android:textSize="12dp"
462
-
463
- app:layout_constraintEnd_toEndOf="parent"
464
-
465
- app:layout_constraintTop_toBottomOf="@id/text_red_mem_num" />
466
-
467
-
468
-
469
-
470
-
471
- </androidx.constraintlayout.widget.ConstraintLayout>
472
-
473
- ```

2

追記

2020/06/27 01:47

投稿

yukari00
yukari00

スコア5

test CHANGED
File without changes
test CHANGED
@@ -30,6 +30,26 @@
30
30
 
31
31
  ```ここに言語を入力
32
32
 
33
+ override fun onCreateView(
34
+
35
+ inflater: LayoutInflater, container: ViewGroup?,
36
+
37
+ savedInstanceState: Bundle?
38
+
39
+ ): View? {
40
+
41
+ // Inflate the layout for this fragment
42
+
43
+ return inflater.inflate(R.layout.fragment_game_setting, container, false)
44
+
45
+ }
46
+
47
+ ```
48
+
49
+
50
+
51
+ ```ここに言語を入力
52
+
33
53
  private fun individualsInfo(
34
54
 
35
55
  teamRed: MutableList<Uid>,

1

追記

2020/06/27 00:44

投稿

yukari00
yukari00

スコア5

test CHANGED
File without changes
test CHANGED
@@ -22,6 +22,12 @@
22
22
 
23
23
 
24
24
 
25
+ <追記>
26
+
27
+ ログを使って調べたところ、多くのテキストビューがnullになっていることがわかり、(全てのテキストビューを調べたわけではないので多くのと書きました)activityもnullになっていたので、もしかしたら何かしらの理由で、普通はフラグメントが開く前に通るところを通っていないんだと思います。
28
+
29
+
30
+
25
31
  ```ここに言語を入力
26
32
 
27
33
  private fun individualsInfo(