質問編集履歴
1
コードの追加と現象の詳細内容
test
CHANGED
File without changes
|
test
CHANGED
@@ -67,3 +67,235 @@
|
|
67
67
|
}
|
68
68
|
|
69
69
|
```
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Bottom NavigationはMainActivityにあり、下記のようなコードで実装しています、ここのHomeFragmentというのがtabLayoutが置いてあるfragmentで、別のfragment(SettingsFragment等)に移動して戻るとviewPagerの中身が表示されなくなってしまいます。別のアクティビティからは下のonClickでMainActivityに遷移しています。
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
また、HomeFragmentでは下のCategoryFragment,RankingFragment,NewArrivalsFragment(中身はRankingFragmentと同じ、テストでLayoutファイルで適当な文字列を表示しています)の3つをviewPagerで表示しているのですが、別のfragmentから戻ったときはCategoryFragmentとRankingFragmentは表示されず、右端のNewArrivalsFragmentだけ正常に表示され、NewArrivalsFragmentを表示してから戻るとCategoryFragmentは元に戻るがRankingFragmentだけはずっと表示されないままです。
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```Java
|
82
|
+
|
83
|
+
BottomNavigationView bottomNavigationView = (BottomNavigationView)
|
84
|
+
|
85
|
+
findViewById(R.id.navigation);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
bottomNavigationView.setOnNavigationItemSelectedListener
|
90
|
+
|
91
|
+
(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
92
|
+
|
93
|
+
@Override
|
94
|
+
|
95
|
+
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
96
|
+
|
97
|
+
Fragment selectedFragment = null;
|
98
|
+
|
99
|
+
switch (item.getItemId()) {
|
100
|
+
|
101
|
+
case R.id.home:
|
102
|
+
|
103
|
+
selectedFragment = new HomeFragment();
|
104
|
+
|
105
|
+
break;
|
106
|
+
|
107
|
+
case R.id.like:
|
108
|
+
|
109
|
+
selectedFragment = new FavoriteFragment();
|
110
|
+
|
111
|
+
break;
|
112
|
+
|
113
|
+
case R.id.settings:
|
114
|
+
|
115
|
+
selectedFragment = new SettingsFragment();
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
120
|
+
|
121
|
+
transaction.replace(R.id.frame_layout, selectedFragment);
|
122
|
+
|
123
|
+
transaction.commit();
|
124
|
+
|
125
|
+
return true;
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
//Manually displaying the first fragment - one time only
|
134
|
+
|
135
|
+
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
136
|
+
|
137
|
+
transaction.replace(R.id.frame_layout, new HomeFragment());
|
138
|
+
|
139
|
+
transaction.commit();
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
```Java
|
146
|
+
|
147
|
+
public void onClick(View view){
|
148
|
+
|
149
|
+
Intent intent = new Intent(this, MainActivity.class);
|
150
|
+
|
151
|
+
startActivity(intent);
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
```Java
|
160
|
+
|
161
|
+
public class CategoryFragment extends Fragment {
|
162
|
+
|
163
|
+
private Intent intent;
|
164
|
+
|
165
|
+
private MainActivity parentMain2;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
@Override
|
170
|
+
|
171
|
+
public void onCreate(Bundle savedInstanceState) {
|
172
|
+
|
173
|
+
super.onCreate(savedInstanceState);
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
@Override
|
180
|
+
|
181
|
+
public void onViewCreated(View view, Bundle savedInstanceState) {
|
182
|
+
|
183
|
+
// ListViewに表示するデータ
|
184
|
+
|
185
|
+
final ArrayList<String> items = new ArrayList<>();
|
186
|
+
|
187
|
+
items.add("1");
|
188
|
+
|
189
|
+
items.add("2");
|
190
|
+
|
191
|
+
items.add("3");
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
// ListViewをセット
|
196
|
+
|
197
|
+
final ArrayAdapter adapter = new ArrayAdapter(this.getContext(), android.R.layout.simple_list_item_1, items);
|
198
|
+
|
199
|
+
ListView listView = view.findViewById(R.id.listView);
|
200
|
+
|
201
|
+
listView.setAdapter(adapter);
|
202
|
+
|
203
|
+
//
|
204
|
+
|
205
|
+
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
206
|
+
|
207
|
+
@Override
|
208
|
+
|
209
|
+
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
210
|
+
|
211
|
+
parentMain2.categoryMove(position);
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
});
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
@Override
|
222
|
+
|
223
|
+
public void onAttach(Context context) {
|
224
|
+
|
225
|
+
parentMain2 = (MainActivity) context;
|
226
|
+
|
227
|
+
super.onAttach(context);
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
@Override
|
234
|
+
|
235
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
236
|
+
|
237
|
+
Bundle savedInstanceState) {
|
238
|
+
|
239
|
+
View view = inflater.inflate(R.layout.fragment_category, null);
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
return view;
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
```Java
|
254
|
+
|
255
|
+
public class RankingFragment extends Fragment {
|
256
|
+
|
257
|
+
@Override
|
258
|
+
|
259
|
+
public void onCreate(Bundle savedInstanceState) {
|
260
|
+
|
261
|
+
super.onCreate(savedInstanceState);
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
@Override
|
272
|
+
|
273
|
+
public void onViewCreated(View view, Bundle savedInstanceState) {
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
@Override
|
284
|
+
|
285
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
286
|
+
|
287
|
+
Bundle savedInstanceState) {
|
288
|
+
|
289
|
+
View view = inflater.inflate(R.layout.fragment_ranking, null);
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
return view;
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
```
|