質問編集履歴
9
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
BottomNavigationViewに最初に表示される予定のFragmentはfirstFragmentです。
|
9
|
+
BottomNavigationViewに最初に表示される予定のFragmentはfirstFragment.javaです。
|
10
10
|
|
11
11
|
画面には一応ナビゲーションバーはきちんと表示されています。
|
12
12
|
|
8
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
MainActivity画面の下部にBottomNavigationViewを作成して、複数のFragment画面に行けるようにしたのですが、2か所でエラーが発生します。
|
4
4
|
|
5
|
-
エラー
|
5
|
+
エラーの箇所を削除してエミュレータを起動しようとすると、アプリが落ちます。
|
6
6
|
|
7
7
|
|
8
8
|
|
7
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -180,110 +180,72 @@
|
|
180
180
|
|
181
181
|
|
182
182
|
|
183
|
-
```
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
a
|
192
|
-
|
193
|
-
at
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
a
|
198
|
-
|
199
|
-
a
|
200
|
-
|
201
|
-
a
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
a
|
208
|
-
|
209
|
-
a
|
210
|
-
|
211
|
-
a
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
a
|
224
|
-
|
225
|
-
a
|
226
|
-
|
227
|
-
a
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
a
|
234
|
-
|
235
|
-
a
|
236
|
-
|
237
|
-
a
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
a
|
244
|
-
|
245
|
-
a
|
246
|
-
|
247
|
-
a
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
at com.example.eiyoukun.MainActivity.onCreate(MainActivity.java:70)
|
254
|
-
|
255
|
-
at android.app.Activity.performCreate(Activity.java:8066)
|
256
|
-
|
257
|
-
at android.app.Activity.performCreate(Activity.java:8054)
|
258
|
-
|
259
|
-
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
|
260
|
-
|
261
|
-
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3733)
|
262
|
-
|
263
|
-
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
|
264
|
-
|
265
|
-
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
|
266
|
-
|
267
|
-
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
|
268
|
-
|
269
|
-
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
|
270
|
-
|
271
|
-
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
|
272
|
-
|
273
|
-
at android.os.Handler.dispatchMessage(Handler.java:107)
|
274
|
-
|
275
|
-
at android.os.Looper.loop(Looper.java:213)
|
276
|
-
|
277
|
-
at android.app.ActivityThread.main(ActivityThread.java:8147)
|
278
|
-
|
279
|
-
at java.lang.reflect.Method.invoke(Native Method)
|
280
|
-
|
281
|
-
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
|
282
|
-
|
283
|
-
2020-09-30 21:15:22.438 32522-32522/com.example.eiyoukun E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
|
284
|
-
|
285
|
-
Caused by: java.lang.ClassCastException
|
286
|
-
|
287
|
-
... 32 more
|
288
|
-
|
289
|
-
```
|
183
|
+
```mynavxml
|
184
|
+
|
185
|
+
<fragment
|
186
|
+
|
187
|
+
android:id="@+id/fragment1"
|
188
|
+
|
189
|
+
android:name="com.example.test.Fragment1"
|
190
|
+
|
191
|
+
android:label="fragment_1"
|
192
|
+
|
193
|
+
tools:layout="@layout/fragment_1" />
|
194
|
+
|
195
|
+
<fragment
|
196
|
+
|
197
|
+
android:id="@+id/fragment2"
|
198
|
+
|
199
|
+
android:name="com.example.test.Fragment2"
|
200
|
+
|
201
|
+
android:label="fragment_2"
|
202
|
+
|
203
|
+
tools:layout="@layout/fragment_2" />
|
204
|
+
|
205
|
+
<fragment
|
206
|
+
|
207
|
+
android:id="@+id/fragment3"
|
208
|
+
|
209
|
+
android:name="com.example.test.Fragment3"
|
210
|
+
|
211
|
+
android:label="fragment_3"
|
212
|
+
|
213
|
+
tools:layout="@layout/fragment_3" />
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
```bottommenuxml
|
220
|
+
|
221
|
+
<fragment
|
222
|
+
|
223
|
+
android:id="@+id/fragment1"
|
224
|
+
|
225
|
+
android:name="com.example.test.Fragment1"
|
226
|
+
|
227
|
+
android:label="fragment_1"
|
228
|
+
|
229
|
+
tools:layout="@layout/fragment_1" />
|
230
|
+
|
231
|
+
<fragment
|
232
|
+
|
233
|
+
android:id="@+id/fragment2"
|
234
|
+
|
235
|
+
android:name="com.example.test.Fragment2"
|
236
|
+
|
237
|
+
android:label="fragment_2"
|
238
|
+
|
239
|
+
tools:layout="@layout/fragment_2" />
|
240
|
+
|
241
|
+
<fragment
|
242
|
+
|
243
|
+
android:id="@+id/fragment3"
|
244
|
+
|
245
|
+
android:name="com.example.test.Fragment3"
|
246
|
+
|
247
|
+
android:label="fragment_3"
|
248
|
+
|
249
|
+
tools:layout="@layout/fragment_3" />
|
250
|
+
|
251
|
+
```
|
6
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -180,176 +180,110 @@
|
|
180
180
|
|
181
181
|
|
182
182
|
|
183
|
-
```
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
android
|
194
|
-
|
195
|
-
android
|
196
|
-
|
197
|
-
too
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
android
|
206
|
-
|
207
|
-
android
|
208
|
-
|
209
|
-
an
|
210
|
-
|
211
|
-
a
|
212
|
-
|
213
|
-
a
|
214
|
-
|
215
|
-
ap
|
216
|
-
|
217
|
-
ap
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
183
|
+
```errormsg
|
184
|
+
|
185
|
+
32522-32522/com.example.eiyoukun E/AndroidRuntime: FATAL EXCEPTION: main
|
186
|
+
|
187
|
+
Process: com.example.eiyoukun, PID: 32522
|
188
|
+
|
189
|
+
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eiyoukun/com.example.eiyoukun.MainActivity}: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
|
190
|
+
|
191
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3760)
|
192
|
+
|
193
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
|
194
|
+
|
195
|
+
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
|
196
|
+
|
197
|
+
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
|
198
|
+
|
199
|
+
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
|
200
|
+
|
201
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
|
202
|
+
|
203
|
+
at android.os.Handler.dispatchMessage(Handler.java:107)
|
204
|
+
|
205
|
+
at android.os.Looper.loop(Looper.java:213)
|
206
|
+
|
207
|
+
at android.app.ActivityThread.main(ActivityThread.java:8147)
|
208
|
+
|
209
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
210
|
+
|
211
|
+
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
|
212
|
+
|
213
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
|
214
|
+
|
215
|
+
Caused by: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
|
216
|
+
|
217
|
+
Caused by: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
|
218
|
+
|
219
|
+
Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class androidx.navigation.fragment.NavHostFragment that is not a Fragment
|
220
|
+
|
221
|
+
at android.app.Fragment.instantiate(Fragment.java:543)
|
222
|
+
|
223
|
+
at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
|
224
|
+
|
225
|
+
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3569)
|
226
|
+
|
227
|
+
at android.app.FragmentController.onCreateView(FragmentController.java:104)
|
228
|
+
|
229
|
+
at android.app.Activity.onCreateView(Activity.java:7202)
|
230
|
+
|
231
|
+
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1079)
|
232
|
+
|
233
|
+
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1007)
|
234
|
+
|
235
|
+
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:971)
|
236
|
+
|
237
|
+
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1133)
|
238
|
+
|
239
|
+
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1094)
|
240
|
+
|
241
|
+
at android.view.LayoutInflater.inflate(LayoutInflater.java:692)
|
242
|
+
|
243
|
+
at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
|
244
|
+
|
245
|
+
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
|
246
|
+
|
247
|
+
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:520)
|
248
|
+
|
249
|
+
at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:328)
|
250
|
+
|
251
|
+
at android.app.Activity.setContentView(Activity.java:3439)
|
252
|
+
|
253
|
+
at com.example.eiyoukun.MainActivity.onCreate(MainActivity.java:70)
|
254
|
+
|
255
|
+
at android.app.Activity.performCreate(Activity.java:8066)
|
256
|
+
|
257
|
+
at android.app.Activity.performCreate(Activity.java:8054)
|
258
|
+
|
259
|
+
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
|
260
|
+
|
261
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3733)
|
262
|
+
|
263
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
|
264
|
+
|
265
|
+
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
|
266
|
+
|
267
|
+
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
|
268
|
+
|
269
|
+
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
|
270
|
+
|
271
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
|
272
|
+
|
273
|
+
at android.os.Handler.dispatchMessage(Handler.java:107)
|
274
|
+
|
275
|
+
at android.os.Looper.loop(Looper.java:213)
|
276
|
+
|
277
|
+
at android.app.ActivityThread.main(ActivityThread.java:8147)
|
278
|
+
|
279
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
280
|
+
|
281
|
+
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
|
282
|
+
|
283
|
+
2020-09-30 21:15:22.438 32522-32522/com.example.eiyoukun E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
|
284
|
+
|
285
|
+
Caused by: java.lang.ClassCastException
|
286
|
+
|
287
|
+
... 32 more
|
222
288
|
|
223
289
|
```
|
224
|
-
|
225
|
-
```firstfragmentjava
|
226
|
-
|
227
|
-
package com.example.eiyoukun;
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
import android.os.Bundle;
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
import androidx.fragment.app.Fragment;
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
import android.view.LayoutInflater;
|
240
|
-
|
241
|
-
import android.view.View;
|
242
|
-
|
243
|
-
import android.view.ViewGroup;
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
/**
|
248
|
-
|
249
|
-
* A simple {@link Fragment} subclass.
|
250
|
-
|
251
|
-
* Use the {@link firstFragment#newInstance} factory method to
|
252
|
-
|
253
|
-
* create an instance of this fragment.
|
254
|
-
|
255
|
-
*/
|
256
|
-
|
257
|
-
public class firstFragment extends Fragment {
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
// TODO: Rename parameter arguments, choose names that match
|
262
|
-
|
263
|
-
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
264
|
-
|
265
|
-
private static final String ARG_PARAM1 = "param1";
|
266
|
-
|
267
|
-
private static final String ARG_PARAM2 = "param2";
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
// TODO: Rename and change types of parameters
|
272
|
-
|
273
|
-
private String mParam1;
|
274
|
-
|
275
|
-
private String mParam2;
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
public firstFragment() {
|
280
|
-
|
281
|
-
// Required empty public constructor
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
/**
|
288
|
-
|
289
|
-
* Use this factory method to create a new instance of
|
290
|
-
|
291
|
-
* this fragment using the provided parameters.
|
292
|
-
|
293
|
-
*
|
294
|
-
|
295
|
-
* @param param1 Parameter 1.
|
296
|
-
|
297
|
-
* @param param2 Parameter 2.
|
298
|
-
|
299
|
-
* @return A new instance of fragment firstFragment.
|
300
|
-
|
301
|
-
*/
|
302
|
-
|
303
|
-
// TODO: Rename and change types and number of parameters
|
304
|
-
|
305
|
-
public static firstFragment newInstance(String param1, String param2) {
|
306
|
-
|
307
|
-
firstFragment fragment = new firstFragment();
|
308
|
-
|
309
|
-
Bundle args = new Bundle();
|
310
|
-
|
311
|
-
args.putString(ARG_PARAM1, param1);
|
312
|
-
|
313
|
-
args.putString(ARG_PARAM2, param2);
|
314
|
-
|
315
|
-
fragment.setArguments(args);
|
316
|
-
|
317
|
-
return fragment;
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
@Override
|
324
|
-
|
325
|
-
public void onCreate(Bundle savedInstanceState) {
|
326
|
-
|
327
|
-
super.onCreate(savedInstanceState);
|
328
|
-
|
329
|
-
if (getArguments() != null) {
|
330
|
-
|
331
|
-
mParam1 = getArguments().getString(ARG_PARAM1);
|
332
|
-
|
333
|
-
mParam2 = getArguments().getString(ARG_PARAM2);
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
}
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
@Override
|
342
|
-
|
343
|
-
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
344
|
-
|
345
|
-
Bundle savedInstanceState) {
|
346
|
-
|
347
|
-
// Inflate the layout for this fragment
|
348
|
-
|
349
|
-
return inflater.inflate(R.layout.fragment_first, container, false);
|
350
|
-
|
351
|
-
}
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
```
|
5
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
作成したFragment.javaと、対するmy_navi.xmlは
|
17
|
+
作成したFragment.javaと、対するmy_navi.xmlのIDは
|
18
18
|
|
19
19
|
・firstFragment.java・・・・fragmentfirst3
|
20
20
|
|
4
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
BottomNavigationViewに最初に表示される予定のFragmentはfirstFragmentです。
|
10
10
|
|
11
11
|
画面には一応ナビゲーションバーはきちんと表示されています。
|
12
12
|
|
3
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
## 分からないこと
|
2
2
|
|
3
|
-
MainActivity画面の下部にBottomNavigationViewを作成して、複数のFragment画面に行けるようにしたのですが、エ
|
3
|
+
MainActivity画面の下部にBottomNavigationViewを作成して、複数のFragment画面に行けるようにしたのですが、2か所でエラーが発生します。
|
4
|
+
|
4
|
-
|
5
|
+
エラーに個所を削除してエミュレータを起動しようとすると、アプリが落ちます。
|
6
|
+
|
7
|
+
|
8
|
+
|
5
|
-
|
9
|
+
MainActivityから最初に遷移する予定のFragmentはfirstFragmentです。
|
6
10
|
|
7
11
|
画面には一応ナビゲーションバーはきちんと表示されています。
|
8
12
|
|
9
13
|
|
10
14
|
|
15
|
+
|
16
|
+
|
11
|
-
作成したFragmentは
|
17
|
+
作成したFragment.javaと、対するmy_navi.xmlは
|
12
|
-
|
18
|
+
|
13
|
-
・firstFragment.java・・・・fragmentfirst3
|
19
|
+
・firstFragment.java・・・・fragmentfirst3
|
14
|
-
|
20
|
+
|
15
|
-
・secondFragment.java・・・・fragmentsecond2
|
21
|
+
・secondFragment.java・・・・fragmentsecond2
|
16
|
-
|
22
|
+
|
17
|
-
・thirdFragment.java・・・・fragmentthird
|
23
|
+
・thirdFragment.java・・・・fragmentthird
|
18
24
|
|
19
25
|
です。
|
20
26
|
|
@@ -22,135 +28,185 @@
|
|
22
28
|
|
23
29
|
## コード
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
a
|
42
|
-
|
43
|
-
a
|
44
|
-
|
45
|
-
a
|
46
|
-
|
47
|
-
a
|
48
|
-
|
49
|
-
a
|
50
|
-
|
51
|
-
a
|
52
|
-
|
53
|
-
at
|
54
|
-
|
55
|
-
a
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
a
|
64
|
-
|
65
|
-
a
|
66
|
-
|
67
|
-
a
|
68
|
-
|
69
|
-
a
|
70
|
-
|
71
|
-
a
|
72
|
-
|
73
|
-
a
|
74
|
-
|
75
|
-
a
|
76
|
-
|
77
|
-
a
|
78
|
-
|
79
|
-
a
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
at android.view.LayoutInflater.inflate(LayoutInflater.java:692)
|
84
|
-
|
85
|
-
at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
|
86
|
-
|
87
|
-
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
|
88
|
-
|
89
|
-
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:520)
|
90
|
-
|
91
|
-
at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:328)
|
92
|
-
|
93
|
-
at android.app.Activity.setContentView(Activity.java:3439)
|
94
|
-
|
95
|
-
at com.example.eiyoukun.MainActivity.onCreate(MainActivity.java:71)
|
96
|
-
|
97
|
-
at android.app.Activity.performCreate(Activity.java:8066)
|
98
|
-
|
99
|
-
at android.app.Activity.performCreate(Activity.java:8054)
|
100
|
-
|
101
|
-
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
|
102
|
-
|
103
|
-
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3733)
|
104
|
-
|
105
|
-
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
|
106
|
-
|
107
|
-
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
|
108
|
-
|
109
|
-
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
|
110
|
-
|
111
|
-
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
|
112
|
-
|
113
|
-
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
|
114
|
-
|
115
|
-
at android.os.Handler.dispatchMessage(Handler.java:107)
|
116
|
-
|
117
|
-
at android.os.Looper.loop(Looper.java:213)
|
118
|
-
|
119
|
-
at android.app.ActivityThread.main(ActivityThread.java:8147)
|
120
|
-
|
121
|
-
at java.lang.reflect.Method.invoke(Native Method)
|
122
|
-
|
123
|
-
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
|
124
|
-
|
125
|
-
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
|
126
|
-
|
127
|
-
Caused by: java.lang.ClassCastException
|
128
|
-
|
129
|
-
... 32 more
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```activitymainxml
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
<中略>
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
<com.google.android.material.bottomnavigation.BottomNavigationView
|
46
|
+
|
47
|
+
android:id="@+id/bottomNavigationView"
|
48
|
+
|
49
|
+
android:background="#fff"
|
50
|
+
|
51
|
+
android:layout_width="411dp"
|
52
|
+
|
53
|
+
android:layout_height="48dp"
|
54
|
+
|
55
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
56
|
+
|
57
|
+
app:layout_constraintEnd_toEndOf="parent"
|
58
|
+
|
59
|
+
app:layout_constraintStart_toStartOf="parent"
|
60
|
+
|
61
|
+
app:menu="@menu/bottom_menu"
|
62
|
+
|
63
|
+
/>
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
<fragment
|
68
|
+
|
69
|
+
android:id="@+id/fragment2"
|
70
|
+
|
71
|
+
android:name="androidx.navigation.fragment.NavHostFragment"
|
72
|
+
|
73
|
+
android:layout_width="416dp"
|
74
|
+
|
75
|
+
android:layout_height="45dp"
|
76
|
+
|
77
|
+
app:defaultNavHost="true"
|
78
|
+
|
79
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
80
|
+
|
81
|
+
app:layout_constraintEnd_toEndOf="parent"
|
82
|
+
|
83
|
+
app:layout_constraintStart_toStartOf="parent"
|
84
|
+
|
85
|
+
app:navGraph="@navigation/my_nav" />
|
86
|
+
|
87
|
+
|
130
88
|
|
131
89
|
```
|
132
90
|
|
133
91
|
|
134
92
|
|
135
|
-
|
136
|
-
|
137
|
-
```activity
|
93
|
+
```mainactivityjava
|
94
|
+
|
138
|
-
|
95
|
+
import androidx.fragment.app.Fragment;
|
96
|
+
|
139
|
-
|
97
|
+
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
98
|
+
|
99
|
+
|
100
|
+
|
140
|
-
|
101
|
+
public class MainActivity extends Activity {
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
private BottomNavigationView.OnNavigationItemSelectedListener navListener =
|
106
|
+
|
107
|
+
new BottomNavigationView.OnNavigationItemSelectedListener() {
|
108
|
+
|
109
|
+
@Override
|
110
|
+
|
111
|
+
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
112
|
+
|
113
|
+
Fragment selectedFragment = null;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
switch (item.getItemId()){
|
118
|
+
|
119
|
+
case R.id.firstFragment3:
|
120
|
+
|
121
|
+
selectedFragment = new firstFragment(); //new firstFragmentに赤線が引かれるがmsgなし
|
122
|
+
|
123
|
+
break;
|
124
|
+
|
125
|
+
case R.id.secondFragment2:
|
126
|
+
|
127
|
+
selectedFragment = new secondFragment();
|
128
|
+
|
129
|
+
break;
|
130
|
+
|
131
|
+
case R.id.thirdFragment:
|
132
|
+
|
133
|
+
selectedFragment = new thirdFragment();
|
134
|
+
|
135
|
+
break;
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
//selectedFragmentに赤線 msgなし
|
140
|
+
|
141
|
+
getFragmentManager().beginTransaction().replace(R.id.fragment_container_view_tag,selectedFragment).commit();
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
return true;
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
};
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
@Override
|
154
|
+
|
155
|
+
protected void onCreate(Bundle savedInstanceState) {
|
156
|
+
|
157
|
+
|
158
|
+
|
141
|
-
<中略>
|
159
|
+
<中略>
|
142
|
-
|
143
|
-
|
144
|
-
|
160
|
+
|
161
|
+
|
162
|
+
|
145
|
-
|
163
|
+
BottomNavigationView bottomNav = findViewById(R.id.bottomNavigationView);
|
164
|
+
|
146
|
-
|
165
|
+
bottomNav.setOnNavigationItemReselectedListener((BottomNavigationView.OnNavigationItemReselectedListener) navListener);
|
166
|
+
|
167
|
+
getFragmentManager().beginTransaction().replace(R.id.fragment_container_view_tag,firstFragment()).commit();
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
```fragmentfirstxml
|
184
|
+
|
185
|
+
<?xml version="1.0" encoding="utf-8"?>
|
186
|
+
|
187
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
188
|
+
|
189
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
190
|
+
|
147
|
-
|
191
|
+
xmlns:tools="http://schemas.android.com/tools"
|
148
|
-
|
192
|
+
|
149
|
-
|
193
|
+
android:layout_width="match_parent"
|
194
|
+
|
150
|
-
|
195
|
+
android:layout_height="match_parent"
|
196
|
+
|
197
|
+
tools:context=".firstFragment">
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
<!-- TODO: Update blank fragment layout -->
|
202
|
+
|
203
|
+
<TextView
|
204
|
+
|
151
|
-
android:layout_width="
|
205
|
+
android:layout_width="216dp"
|
152
|
-
|
206
|
+
|
153
|
-
android:layout_height="
|
207
|
+
android:layout_height="167dp"
|
208
|
+
|
209
|
+
android:text="first_fragment"
|
154
210
|
|
155
211
|
app:layout_constraintBottom_toBottomOf="parent"
|
156
212
|
|
@@ -158,121 +214,141 @@
|
|
158
214
|
|
159
215
|
app:layout_constraintStart_toStartOf="parent"
|
160
216
|
|
161
|
-
app:menu="@menu/bottom_menu"
|
162
|
-
|
163
|
-
/>
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
<fragment
|
168
|
-
|
169
|
-
android:id="@+id/fragment2"
|
170
|
-
|
171
|
-
android:name="androidx.navigation.fragment.NavHostFragment"
|
172
|
-
|
173
|
-
android:layout_width="416dp"
|
174
|
-
|
175
|
-
android:layout_height="45dp"
|
176
|
-
|
177
|
-
app:defaultNavHost="true"
|
178
|
-
|
179
|
-
app:layout_constraintBottom_toBottomOf="parent"
|
180
|
-
|
181
|
-
app:layout_constraint
|
217
|
+
app:layout_constraintTop_toTopOf="parent" />
|
182
|
-
|
218
|
+
|
219
|
+
|
220
|
+
|
183
|
-
|
221
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
184
|
-
|
185
|
-
app:navGraph="@navigation/my_nav" />
|
186
|
-
|
187
|
-
|
188
222
|
|
189
223
|
```
|
190
224
|
|
191
|
-
|
192
|
-
|
193
|
-
```m
|
225
|
+
```firstfragmentjava
|
226
|
+
|
227
|
+
package com.example.eiyoukun;
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
import android.os.Bundle;
|
232
|
+
|
233
|
+
|
194
234
|
|
195
235
|
import androidx.fragment.app.Fragment;
|
196
236
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
p
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
pr
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
237
|
+
|
238
|
+
|
239
|
+
import android.view.LayoutInflater;
|
240
|
+
|
241
|
+
import android.view.View;
|
242
|
+
|
243
|
+
import android.view.ViewGroup;
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
/**
|
248
|
+
|
249
|
+
* A simple {@link Fragment} subclass.
|
250
|
+
|
251
|
+
* Use the {@link firstFragment#newInstance} factory method to
|
252
|
+
|
253
|
+
* create an instance of this fragment.
|
254
|
+
|
255
|
+
*/
|
256
|
+
|
257
|
+
public class firstFragment extends Fragment {
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
// TODO: Rename parameter arguments, choose names that match
|
262
|
+
|
263
|
+
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
264
|
+
|
265
|
+
private static final String ARG_PARAM1 = "param1";
|
266
|
+
|
267
|
+
private static final String ARG_PARAM2 = "param2";
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
// TODO: Rename and change types of parameters
|
272
|
+
|
273
|
+
private String mParam1;
|
274
|
+
|
275
|
+
private String mParam2;
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
public firstFragment() {
|
280
|
+
|
281
|
+
// Required empty public constructor
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
/**
|
288
|
+
|
289
|
+
* Use this factory method to create a new instance of
|
290
|
+
|
291
|
+
* this fragment using the provided parameters.
|
292
|
+
|
293
|
+
*
|
294
|
+
|
295
|
+
* @param param1 Parameter 1.
|
296
|
+
|
297
|
+
* @param param2 Parameter 2.
|
298
|
+
|
299
|
+
* @return A new instance of fragment firstFragment.
|
300
|
+
|
301
|
+
*/
|
302
|
+
|
303
|
+
// TODO: Rename and change types and number of parameters
|
304
|
+
|
305
|
+
public static firstFragment newInstance(String param1, String param2) {
|
306
|
+
|
307
|
+
firstFragment fragment = new firstFragment();
|
308
|
+
|
309
|
+
Bundle args = new Bundle();
|
310
|
+
|
311
|
+
args.putString(ARG_PARAM1, param1);
|
312
|
+
|
313
|
+
args.putString(ARG_PARAM2, param2);
|
314
|
+
|
315
|
+
fragment.setArguments(args);
|
316
|
+
|
317
|
+
return fragment;
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
@Override
|
324
|
+
|
325
|
+
public void onCreate(Bundle savedInstanceState) {
|
326
|
+
|
327
|
+
super.onCreate(savedInstanceState);
|
328
|
+
|
329
|
+
if (getArguments() != null) {
|
330
|
+
|
331
|
+
mParam1 = getArguments().getString(ARG_PARAM1);
|
332
|
+
|
333
|
+
mParam2 = getArguments().getString(ARG_PARAM2);
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
@Override
|
342
|
+
|
343
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
344
|
+
|
345
|
+
Bundle savedInstanceState) {
|
346
|
+
|
347
|
+
// Inflate the layout for this fragment
|
348
|
+
|
349
|
+
return inflater.inflate(R.layout.fragment_first, container, false);
|
350
|
+
|
351
|
+
}
|
276
352
|
|
277
353
|
|
278
354
|
|
2
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,11 +18,7 @@
|
|
18
18
|
|
19
19
|
です。
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
![イメージ説明](5cc6b993b704609a4bf5d26fed5af1c3.png)
|
24
|
-
|
25
|
-
|
26
22
|
|
27
23
|
## コード
|
28
24
|
|
1
内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
E/AndroidRuntime: FATAL EXCEPTION: main
|
32
32
|
|
33
|
-
Process: com.example.eiyoukun, PID:
|
33
|
+
Process: com.example.eiyoukun, PID:
|
34
34
|
|
35
35
|
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eiyoukun/com.example.eiyoukun.MainActivity}: android.view.InflateException: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Binary XML file line #379 in com.example.eiyoukun:layout/activity_main: Error inflating class fragment
|
36
36
|
|