質問編集履歴
1
問題②のエラーが消えたのでエラー内容は削除しました。また、コメントを受けて試したことを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,63 +40,439 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
### ②個別のアクティビティを指定する(今回の場合は画面遷移)`SubActivity.kt`について
|
43
|
+
### ②個別のアクティビティを指定する(今回の場合は画面遷移)`SubActivity.kt`について
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
-
|
47
|
+
2-1. `AndroidManifest.xml`でフラグメントと組み合わせる場合は、現在の書き方で正しいのかどうか
|
48
|
+
|
49
|
+
|
50
|
+
|
48
|
-
|
51
|
+
2-2. `SubActivity.kt`という名称で現在の階層構造のように`ui`フォルダ下の各フラグメントのファイルにおいていいのか
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
エラーは出ていないが、似たようなことをやっているコードを見たことがないため、参考になる記事などがあれば教えていただきたいです。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
## 該当のソースコード
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
フラグメントに組み込みたいMainActivity.kt
|
68
|
+
|
69
|
+
```kotlin
|
70
|
+
|
71
|
+
package your.package.name
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
import androidx.appcompat.app.AppCompatActivity
|
76
|
+
|
77
|
+
import android.os.Bundle
|
78
|
+
|
79
|
+
import android.content.Intent
|
80
|
+
|
81
|
+
import kotlinx.android.synthetic.main.activity_main.*
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
class MainActivity : AppCompatActivity() {
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
90
|
+
|
91
|
+
super.onCreate(savedInstanceState)
|
92
|
+
|
93
|
+
setContentView(R.layout.activity_main)
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
sendButton.setOnClickListener {
|
98
|
+
|
99
|
+
val intent = Intent(application, SubActivity::class.java)
|
100
|
+
|
101
|
+
startActivity(intent)
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
49
|
-
```
|
109
|
+
```
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
DashboardFragment.kt
|
114
|
+
|
115
|
+
```Kotlin
|
116
|
+
|
117
|
+
package com.example.fragact.ui.dashboard
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
import android.os.Bundle
|
122
|
+
|
123
|
+
import android.view.LayoutInflater
|
124
|
+
|
125
|
+
import android.view.View
|
126
|
+
|
127
|
+
import android.view.ViewGroup
|
128
|
+
|
129
|
+
import android.widget.TextView
|
130
|
+
|
131
|
+
import androidx.fragment.app.Fragment
|
132
|
+
|
133
|
+
import androidx.lifecycle.Observer
|
134
|
+
|
135
|
+
import androidx.lifecycle.ViewModelProviders
|
136
|
+
|
137
|
+
import com.example.fragact.R
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
class DashboardFragment : Fragment() {
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
private lateinit var dashboardViewModel: DashboardViewModel
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
override fun onCreateView(
|
150
|
+
|
151
|
+
inflater: LayoutInflater,
|
152
|
+
|
153
|
+
container: ViewGroup?,
|
154
|
+
|
155
|
+
savedInstanceState: Bundle?
|
156
|
+
|
157
|
+
): View? {
|
158
|
+
|
159
|
+
dashboardViewModel =
|
160
|
+
|
161
|
+
ViewModelProviders.of(this).get(DashboardViewModel::class.java)
|
162
|
+
|
163
|
+
val root = inflater.inflate(R.layout.fragment_dashboard, container, false)
|
164
|
+
|
165
|
+
val textView: TextView = root.findViewById(R.id.text_dashboard)
|
166
|
+
|
167
|
+
dashboardViewModel.text.observe(this, Observer {
|
168
|
+
|
169
|
+
textView.text = it
|
170
|
+
|
171
|
+
})
|
172
|
+
|
173
|
+
return root
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
DashboardViewModel.kt
|
182
|
+
|
183
|
+
```kotlin
|
184
|
+
|
185
|
+
package com.example.fragact.ui.dashboard
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
import androidx.lifecycle.LiveData
|
190
|
+
|
191
|
+
import androidx.lifecycle.MutableLiveData
|
192
|
+
|
193
|
+
import androidx.lifecycle.ViewModel
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
class DashboardViewModel : ViewModel() {
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
private val _text = MutableLiveData<String>().apply {
|
202
|
+
|
203
|
+
value = "This is dashboard Fragment"
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
val text: LiveData<String> = _text
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
```
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
`app/java/com.example.fracact/ui/dashboard/`
|
216
|
+
|
217
|
+
SubActivity.kt
|
218
|
+
|
219
|
+
```
|
220
|
+
|
221
|
+
package com.example.fragact.ui.dashboard
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
import androidx.appcompat.app.AppCompatActivity
|
226
|
+
|
227
|
+
import android.os.Bundle
|
228
|
+
|
229
|
+
import kotlinx.android.synthetic.main.activity_sub.*
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
class SubActivity : AppCompatActivity() {
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
238
|
+
|
239
|
+
super.onCreate(savedInstanceState)
|
240
|
+
|
241
|
+
setContentView(R.layout.activity_sub)
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
returnButton.setOnClickListener{
|
246
|
+
|
247
|
+
finish()
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
AndroidManifest.xml
|
262
|
+
|
263
|
+
```xml
|
264
|
+
|
265
|
+
<?xml version="1.0" encoding="utf-8"?>
|
266
|
+
|
267
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
268
|
+
|
269
|
+
package="com.example.fragact">
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
<application
|
274
|
+
|
275
|
+
android:allowBackup="true"
|
276
|
+
|
277
|
+
android:icon="@mipmap/ic_launcher"
|
278
|
+
|
279
|
+
android:label="@string/app_name"
|
280
|
+
|
281
|
+
android:roundIcon="@mipmap/ic_launcher_round"
|
282
|
+
|
283
|
+
android:supportsRtl="true"
|
284
|
+
|
285
|
+
android:theme="@style/AppTheme">
|
50
286
|
|
51
287
|
<activity
|
52
288
|
|
289
|
+
android:name=".MainActivity"
|
290
|
+
|
291
|
+
android:label="@string/app_name">
|
292
|
+
|
293
|
+
<intent-filter>
|
294
|
+
|
295
|
+
<action android:name="android.intent.action.MAIN" />
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
300
|
+
|
301
|
+
</intent-filter>
|
302
|
+
|
303
|
+
</activity>
|
304
|
+
|
305
|
+
<activity
|
306
|
+
|
53
307
|
android:name=".SubActivity"
|
54
308
|
|
55
309
|
android:label="@string/app_name" >
|
56
310
|
|
57
311
|
</activity>
|
58
312
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
```
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
```
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
313
|
+
</application>
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
</manifest>
|
318
|
+
|
319
|
+
```
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
## 試したこと
|
328
|
+
|
329
|
+
`DashboardFragment.kt`などアクティビティに関わるプログラムを変更せず、layoutだけ変更した場合、アクティビティなしの遷移前の画面は表示することができました。
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
fragment_dashboard.xml
|
334
|
+
|
335
|
+
```xml
|
336
|
+
|
337
|
+
<?xml version="1.0" encoding="utf-8"?>
|
338
|
+
|
339
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
340
|
+
|
341
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
342
|
+
|
343
|
+
android:layout_width="match_parent"
|
344
|
+
|
345
|
+
android:layout_height="match_parent">
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
<TextView
|
350
|
+
|
351
|
+
android:id="@+id/text_dashboard"
|
352
|
+
|
353
|
+
android:layout_width="match_parent"
|
354
|
+
|
355
|
+
android:layout_height="wrap_content"
|
356
|
+
|
357
|
+
android:layout_marginStart="8dp"
|
358
|
+
|
359
|
+
android:layout_marginTop="8dp"
|
360
|
+
|
361
|
+
android:layout_marginEnd="8dp"
|
362
|
+
|
363
|
+
android:textAlignment="center"
|
364
|
+
|
365
|
+
android:textSize="20sp"
|
366
|
+
|
367
|
+
app:layout_constraintEnd_toEndOf="parent"
|
368
|
+
|
369
|
+
app:layout_constraintStart_toStartOf="parent"
|
370
|
+
|
371
|
+
app:layout_constraintTop_toTopOf="parent" />
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
376
|
+
|
377
|
+
xmlns:tools="http://schemas.android.com/tools"
|
378
|
+
|
379
|
+
android:layout_width="match_parent"
|
380
|
+
|
381
|
+
android:layout_height="match_parent"
|
382
|
+
|
383
|
+
android:orientation="vertical"
|
384
|
+
|
385
|
+
android:gravity="center"
|
386
|
+
|
387
|
+
android:background="#dfe"
|
388
|
+
|
389
|
+
tools:context=".MainActivity">
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
<TextView
|
394
|
+
|
395
|
+
android:text="@string/main"
|
396
|
+
|
397
|
+
android:textSize="30sp"
|
398
|
+
|
399
|
+
android:layout_margin="10dp"
|
400
|
+
|
401
|
+
android:layout_width="wrap_content"
|
402
|
+
|
403
|
+
android:layout_height="wrap_content" />
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
<Button
|
408
|
+
|
409
|
+
android:id="@+id/sendButton"
|
410
|
+
|
411
|
+
android:text="@string/move"
|
412
|
+
|
413
|
+
android:textSize="30sp"
|
414
|
+
|
415
|
+
android:layout_margin="20dp"
|
416
|
+
|
417
|
+
android:layout_width="wrap_content"
|
418
|
+
|
419
|
+
android:layout_height="wrap_content" />
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
</LinearLayout>
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
430
|
+
|
431
|
+
```
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
## コメントを受けて試したこと
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
app/java/com.example.fragact/MainActivityに組み込みたいMainActivity.ktの内容を追記してみました。
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
MainActivity
|
446
|
+
|
447
|
+
```
|
448
|
+
|
449
|
+
package com.example.fragact
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
import android.os.Bundle
|
454
|
+
|
455
|
+
import com.google.android.material.bottomnavigation.BottomNavigationView
|
86
456
|
|
87
457
|
import androidx.appcompat.app.AppCompatActivity
|
88
458
|
|
89
|
-
import android.o
|
459
|
+
import androidx.navigation.findNavController
|
460
|
+
|
461
|
+
import androidx.navigation.ui.AppBarConfiguration
|
462
|
+
|
463
|
+
import androidx.navigation.ui.setupActionBarWithNavController
|
464
|
+
|
465
|
+
import androidx.navigation.ui.setupWithNavController
|
90
466
|
|
91
467
|
import android.content.Intent
|
92
468
|
|
93
469
|
import kotlinx.android.synthetic.main.activity_main.*
|
94
470
|
|
95
|
-
|
471
|
+
|
96
472
|
|
97
473
|
class MainActivity : AppCompatActivity() {
|
98
474
|
|
99
|
-
|
475
|
+
|
100
476
|
|
101
477
|
override fun onCreate(savedInstanceState: Bundle?) {
|
102
478
|
|
@@ -104,343 +480,99 @@
|
|
104
480
|
|
105
481
|
setContentView(R.layout.activity_main)
|
106
482
|
|
107
|
-
|
483
|
+
val navView: BottomNavigationView = findViewById(R.id.nav_view)
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
val navController = findNavController(R.id.nav_host_fragment)
|
488
|
+
|
489
|
+
// Passing each menu ID as a set of Ids because each
|
490
|
+
|
491
|
+
// menu should be considered as top level destinations.
|
492
|
+
|
493
|
+
val appBarConfiguration = AppBarConfiguration(
|
494
|
+
|
495
|
+
setOf(
|
496
|
+
|
497
|
+
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
|
498
|
+
|
499
|
+
)
|
500
|
+
|
501
|
+
)
|
502
|
+
|
503
|
+
setupActionBarWithNavController(navController, appBarConfiguration)
|
504
|
+
|
505
|
+
navView.setupWithNavController(navController)
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
|
108
510
|
|
109
511
|
sendButton.setOnClickListener {
|
110
512
|
|
111
|
-
|
513
|
+
val intent = Intent(application, SubActivity::class.java)
|
112
|
-
|
514
|
+
|
113
|
-
|
515
|
+
startActivity(intent)
|
114
516
|
|
115
517
|
}
|
116
518
|
|
117
519
|
}
|
118
520
|
|
521
|
+
|
522
|
+
|
119
523
|
}
|
120
524
|
|
121
525
|
```
|
122
526
|
|
123
527
|
|
124
528
|
|
125
|
-
DashboardFragment.kt
|
126
|
-
|
127
|
-
```Kotlin
|
128
|
-
|
129
|
-
package com.example.fragact.ui.dashboard
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
import android.os.Bundle
|
134
|
-
|
135
|
-
import android.view.LayoutInflater
|
136
|
-
|
137
|
-
import android.view.View
|
138
|
-
|
139
|
-
import android.view.ViewGroup
|
140
|
-
|
141
|
-
import android.widget.TextView
|
142
|
-
|
143
|
-
import androidx.fragment.app.Fragment
|
144
|
-
|
145
|
-
import androidx.lifecycle.Observer
|
146
|
-
|
147
|
-
import androidx.lifecycle.ViewModelProviders
|
148
|
-
|
149
|
-
import com.example.fragact.R
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
class DashboardFragment : Fragment() {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
private lateinit var dashboardViewModel: DashboardViewModel
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
override fun onCreateView(
|
162
|
-
|
163
|
-
inflater: LayoutInflater,
|
164
|
-
|
165
|
-
container: ViewGroup?,
|
166
|
-
|
167
|
-
savedInstanceState: Bundle?
|
168
|
-
|
169
|
-
): View? {
|
170
|
-
|
171
|
-
dashboardViewModel =
|
172
|
-
|
173
|
-
ViewModelProviders.of(this).get(DashboardViewModel::class.java)
|
174
|
-
|
175
|
-
val root = inflater.inflate(R.layout.fragment_dashboard, container, false)
|
176
|
-
|
177
|
-
val textView: TextView = root.findViewById(R.id.text_dashboard)
|
178
|
-
|
179
|
-
dashboardViewModel.text.observe(this, Observer {
|
180
|
-
|
181
|
-
textView.text = it
|
182
|
-
|
183
|
-
|
529
|
+
しかし、
|
184
|
-
|
185
|
-
|
530
|
+
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
```
|
531
|
+
```
|
192
|
-
|
193
|
-
|
532
|
+
|
194
|
-
|
195
|
-
```kotlin
|
196
|
-
|
197
|
-
package com.example.fragact.ui.dashboard
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
import androidx.lifecycle.LiveData
|
202
|
-
|
203
|
-
import androidx.lifecycle.MutableLiveData
|
204
|
-
|
205
|
-
import androidx.lifecycle.ViewModel
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
class DashboardViewModel : ViewModel() {
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
private val _text = MutableLiveData<String>().apply {
|
214
|
-
|
215
|
-
value = "This is dashboard Fragment"
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
val text: LiveData<String> = _text
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
```
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
`app/java/com.example.fracact/ui/dashboard/`
|
228
|
-
|
229
|
-
SubActivity.kt
|
230
|
-
|
231
|
-
```
|
232
|
-
|
233
|
-
package com.example.fragact.ui.dashboard
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
import androidx.appcompat.app.AppCompatActivity
|
238
|
-
|
239
|
-
import android.os.Bundle
|
240
|
-
|
241
|
-
import kotlinx.android.synthetic.main.activity_sub.*
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
class SubActivity : AppCompatActivity() {
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
250
|
-
|
251
|
-
super.onCreate(savedInstanceState)
|
252
|
-
|
253
|
-
setContentView(R.layout.activity_sub)
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
533
|
+
sendButton.setOnClickListener {
|
534
|
+
|
258
|
-
|
535
|
+
val intent = Intent(application, SubActivity::class.java)
|
536
|
+
|
259
|
-
|
537
|
+
startActivity(intent)
|
260
538
|
|
261
539
|
}
|
262
540
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
<activity
|
300
|
-
|
301
|
-
android:name=".MainActivity"
|
302
|
-
|
303
|
-
android:label="@string/app_name">
|
304
|
-
|
305
|
-
<intent-filter>
|
306
|
-
|
307
|
-
<action android:name="android.intent.action.MAIN" />
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
<category android:name="android.intent.category.LAUNCHER" />
|
312
|
-
|
313
|
-
</intent-filter>
|
314
|
-
|
315
|
-
</activity>
|
316
|
-
|
317
|
-
<activity
|
318
|
-
|
319
|
-
android:name=".SubActivity"
|
320
|
-
|
321
|
-
android:label="@string/app_name" >
|
322
|
-
|
323
|
-
</activity>
|
324
|
-
|
325
|
-
</application>
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
</manifest>
|
330
|
-
|
331
|
-
```
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
## 試したこと
|
340
|
-
|
341
|
-
`DashboardFragment.kt`などアクティビティに関わるプログラムを変更せず、layoutだけ変更した場合、アクティビティなしの遷移前の画面は表示することができました。
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
fragment_dashboard.xml
|
346
|
-
|
347
|
-
```xml
|
348
|
-
|
349
|
-
<?xml version="1.0" encoding="utf-8"?>
|
350
|
-
|
351
|
-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
352
|
-
|
353
|
-
xmlns:app="http://schemas.android.com/apk/res-auto"
|
354
|
-
|
355
|
-
android:layout_width="match_parent"
|
356
|
-
|
357
|
-
android:layout_height="match_parent">
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
<TextView
|
362
|
-
|
363
|
-
android:id="@+id/text_dashboard"
|
364
|
-
|
365
|
-
android:layout_width="match_parent"
|
366
|
-
|
367
|
-
android:layout_height="wrap_content"
|
368
|
-
|
369
|
-
android:layout_marginStart="8dp"
|
370
|
-
|
371
|
-
android:layout_marginTop="8dp"
|
372
|
-
|
373
|
-
android:layout_marginEnd="8dp"
|
374
|
-
|
375
|
-
android:textAlignment="center"
|
376
|
-
|
377
|
-
android:textSize="20sp"
|
378
|
-
|
379
|
-
app:layout_constraintEnd_toEndOf="parent"
|
380
|
-
|
381
|
-
app:layout_constraintStart_toStartOf="parent"
|
382
|
-
|
383
|
-
app:layout_constraintTop_toTopOf="parent" />
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
388
|
-
|
389
|
-
xmlns:tools="http://schemas.android.com/tools"
|
390
|
-
|
391
|
-
android:layout_width="match_parent"
|
392
|
-
|
393
|
-
android:layout_height="match_parent"
|
394
|
-
|
395
|
-
android:orientation="vertical"
|
396
|
-
|
397
|
-
android:gravity="center"
|
398
|
-
|
399
|
-
android:background="#dfe"
|
400
|
-
|
401
|
-
tools:context=".MainActivity">
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
<TextView
|
406
|
-
|
407
|
-
android:text="@string/main"
|
408
|
-
|
409
|
-
android:textSize="30sp"
|
410
|
-
|
411
|
-
android:layout_margin="10dp"
|
412
|
-
|
413
|
-
android:layout_width="wrap_content"
|
414
|
-
|
415
|
-
android:layout_height="wrap_content" />
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
<Button
|
420
|
-
|
421
|
-
android:id="@+id/sendButton"
|
422
|
-
|
423
|
-
android:text="@string/move"
|
424
|
-
|
425
|
-
android:textSize="30sp"
|
426
|
-
|
427
|
-
android:layout_margin="20dp"
|
428
|
-
|
429
|
-
android:layout_width="wrap_content"
|
430
|
-
|
431
|
-
android:layout_height="wrap_content" />
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
</LinearLayout>
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
</androidx.constraintlayout.widget.ConstraintLayout>
|
442
|
-
|
443
|
-
```
|
541
|
+
```
|
542
|
+
|
543
|
+
で`sendButton`が`Unresolved reference`となります。
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
layoutのactivity_main.xmlではなく、fragment_dashboard.xmlで「sendButton」を定義していることも原因かと考えられますが、フラグメントごとにアクティビティやレイアウトを設定するには他に方法がわからない状態です。
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
```
|
552
|
+
|
553
|
+
<Button
|
554
|
+
|
555
|
+
android:id="@+id/sendButton"
|
556
|
+
|
557
|
+
android:text="@string/move"
|
558
|
+
|
559
|
+
android:textSize="30sp"
|
560
|
+
|
561
|
+
android:layout_margin="20dp"
|
562
|
+
|
563
|
+
android:layout_width="wrap_content"
|
564
|
+
|
565
|
+
android:layout_height="wrap_content" />
|
566
|
+
|
567
|
+
```
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
|
444
576
|
|
445
577
|
|
446
578
|
|