質問編集履歴
5
mainactivityの再現に不要なdestroyは削除しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -186,48 +186,6 @@
|
|
186
186
|
|
187
187
|
}
|
188
188
|
|
189
|
-
public void destroyAllItem(ViewPager pager) {
|
190
|
-
|
191
|
-
for (int i = 0; i < getCount() - 1; i++) {
|
192
|
-
|
193
|
-
try {
|
194
|
-
|
195
|
-
Object obj = this.instantiateItem(pager, i);
|
196
|
-
|
197
|
-
if (obj != null)
|
198
|
-
|
199
|
-
destroyItem(pager, i, obj);
|
200
|
-
|
201
|
-
} catch (Exception e) {
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
@Override
|
210
|
-
|
211
|
-
public void destroyItem(ViewGroup container, int position, Object object) {
|
212
|
-
|
213
|
-
super.destroyItem(container, position, object);
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
if (position <= getCount()) {
|
218
|
-
|
219
|
-
FragmentManager manager = ((Fragment) object).getFragmentManager();
|
220
|
-
|
221
|
-
FragmentTransaction trans = manager.beginTransaction();
|
222
|
-
|
223
|
-
trans.remove((Fragment) object);
|
224
|
-
|
225
|
-
trans.commit();
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
189
|
}
|
232
190
|
|
233
191
|
public void button1(View v) {
|
4
customtabを削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -431,37 +431,3 @@
|
|
431
431
|
</RelativeLayout>
|
432
432
|
|
433
433
|
```
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
customtabを追記します
|
438
|
-
|
439
|
-
```xml
|
440
|
-
|
441
|
-
<?xml version="1.0" encoding="utf-8"?>
|
442
|
-
|
443
|
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
444
|
-
|
445
|
-
android:layout_width="75dp"
|
446
|
-
|
447
|
-
android:layout_height="match_parent">
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
<ImageView
|
452
|
-
|
453
|
-
android:layout_width="match_parent"
|
454
|
-
|
455
|
-
android:layout_height="53dp"
|
456
|
-
|
457
|
-
android:scaleType="fitCenter"
|
458
|
-
|
459
|
-
android:id="@+id/icon"
|
460
|
-
|
461
|
-
android:layout_gravity="center"
|
462
|
-
|
463
|
-
android:gravity="center"/>
|
464
|
-
|
465
|
-
</LinearLayout>
|
466
|
-
|
467
|
-
```
|
3
最小のプログラムに記載を修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,93 +2,435 @@
|
|
2
2
|
|
3
3
|
以下のようにViewPagerを利用していますが、setCurrentItemが正常に動作してくれません。
|
4
4
|
|
5
|
-
|
5
|
+
以下のプロジェクトでbutton1を押して1−0を選択した後にbutton2を押すとなぜか一つずれて表示されてしまいます。
|
6
|
-
|
6
|
+
|
7
|
-
|
7
|
+
(tabFragmentは作成し変更情報のみ記載してます。)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
何か分かればアドバイスをお願いします。
|
8
12
|
|
9
13
|
|
10
14
|
|
11
15
|
```Java
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
tabLayout
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
17
|
+
public class MainActivity extends AppCompatActivity implements ViewTreeObserver.OnGlobalLayoutListener, tabFragment.OnFragmentInteractionListener {
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
private SectionsPagerAdapter mSectionsPagerAdapter;
|
22
|
+
|
23
|
+
private ViewPager mViewPager1;
|
24
|
+
|
25
|
+
private ViewPager mViewPager2;
|
26
|
+
|
27
|
+
private TabLayout tabLayout;
|
28
|
+
|
29
|
+
private tabFragment mTabFragment;
|
30
|
+
|
31
|
+
int viewFlag = 1;
|
32
|
+
|
33
|
+
@Override
|
34
|
+
|
35
|
+
protected void onCreate(Bundle savedInstanceState) {
|
36
|
+
|
37
|
+
super.onCreate(savedInstanceState);
|
38
|
+
|
39
|
+
setContentView(R.layout.activity_main);
|
40
|
+
|
41
|
+
setTabicons(0);
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
private void setTabicons(int setTub) {
|
48
|
+
|
49
|
+
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
50
|
+
|
51
|
+
mViewPager1 = (ViewPager) findViewById(R.id.container1);
|
52
|
+
|
53
|
+
mViewPager2 = (ViewPager) findViewById(R.id.container2);
|
54
|
+
|
55
|
+
tabLayout = (TabLayout) findViewById(R.id.tabs);
|
56
|
+
|
57
|
+
if (viewFlag == 1) {
|
58
|
+
|
59
|
+
mViewPager1.setVisibility(View.VISIBLE);
|
60
|
+
|
61
|
+
mViewPager2.setVisibility(View.GONE);
|
62
|
+
|
63
|
+
mViewPager1.setAdapter(mSectionsPagerAdapter);
|
64
|
+
|
65
|
+
tabLayout.setupWithViewPager(mViewPager1);
|
66
|
+
|
67
|
+
} else {
|
68
|
+
|
69
|
+
mViewPager1.setVisibility(View.GONE);
|
70
|
+
|
71
|
+
mViewPager2.setVisibility(View.VISIBLE);
|
72
|
+
|
73
|
+
mViewPager2.setAdapter(mSectionsPagerAdapter);
|
74
|
+
|
75
|
+
tabLayout.setupWithViewPager(mViewPager2);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
tabLayout.getViewTreeObserver().addOnGlobalLayoutListener(this);
|
80
|
+
|
81
|
+
if (viewFlag == 1) {
|
82
|
+
|
83
|
+
for (int i = 0; i < 16; i++) {
|
84
|
+
|
85
|
+
tabLayout.getTabAt(i).setText("1-" + String.valueOf(i));
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
} else {
|
90
|
+
|
91
|
+
for (int i = 0; i < 6; i++) {
|
92
|
+
|
93
|
+
tabLayout.getTabAt(i).setText("2-" + String.valueOf(i));
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
if (viewFlag == 1) {
|
100
|
+
|
101
|
+
mViewPager1.setCurrentItem(setTub);
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
mSectionsPagerAdapter.finishUpdate(mViewPager1);
|
106
|
+
|
107
|
+
mSectionsPagerAdapter.finishUpdate(mViewPager2);
|
108
|
+
|
109
|
+
} else {
|
110
|
+
|
111
|
+
mViewPager2.setCurrentItem(setTub);
|
112
|
+
|
113
|
+
mSectionsPagerAdapter.finishUpdate(mViewPager2);
|
114
|
+
|
115
|
+
mSectionsPagerAdapter.finishUpdate(mViewPager1);
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
@Override
|
122
|
+
|
123
|
+
public void onFragmentInteraction(Uri uri) {
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
|
130
|
+
|
131
|
+
public SectionsPagerAdapter(FragmentManager fm) {
|
132
|
+
|
133
|
+
super(fm);
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
@Override
|
138
|
+
|
139
|
+
public Fragment getItem(int position) {
|
140
|
+
|
141
|
+
tabFragment npanel1 = tabFragment.newInstance(position);
|
142
|
+
|
143
|
+
return npanel1;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
@Override
|
148
|
+
|
149
|
+
public int getCount() {
|
150
|
+
|
151
|
+
if (viewFlag == 1) {
|
152
|
+
|
153
|
+
return 16;
|
154
|
+
|
155
|
+
} else {
|
156
|
+
|
157
|
+
return 6;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
@Override
|
164
|
+
|
165
|
+
public CharSequence getPageTitle(int position) {
|
166
|
+
|
167
|
+
return null;
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
@Override
|
172
|
+
|
173
|
+
public Object instantiateItem(ViewGroup container, int position) {
|
174
|
+
|
175
|
+
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
|
176
|
+
|
177
|
+
return createdFragment;
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
@Override
|
182
|
+
|
183
|
+
public int getItemPosition(Object object) {
|
184
|
+
|
185
|
+
return POSITION_NONE;
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
public void destroyAllItem(ViewPager pager) {
|
190
|
+
|
191
|
+
for (int i = 0; i < getCount() - 1; i++) {
|
192
|
+
|
193
|
+
try {
|
194
|
+
|
195
|
+
Object obj = this.instantiateItem(pager, i);
|
196
|
+
|
197
|
+
if (obj != null)
|
198
|
+
|
199
|
+
destroyItem(pager, i, obj);
|
200
|
+
|
201
|
+
} catch (Exception e) {
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
@Override
|
210
|
+
|
211
|
+
public void destroyItem(ViewGroup container, int position, Object object) {
|
212
|
+
|
213
|
+
super.destroyItem(container, position, object);
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
if (position <= getCount()) {
|
218
|
+
|
219
|
+
FragmentManager manager = ((Fragment) object).getFragmentManager();
|
220
|
+
|
221
|
+
FragmentTransaction trans = manager.beginTransaction();
|
222
|
+
|
223
|
+
trans.remove((Fragment) object);
|
224
|
+
|
225
|
+
trans.commit();
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
public void button1(View v) {
|
234
|
+
|
235
|
+
viewFlag = 1;
|
236
|
+
|
237
|
+
setTabicons(mViewPager2.getCurrentItem());
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
public void button2(View v) {
|
242
|
+
|
243
|
+
viewFlag = 2;
|
244
|
+
|
245
|
+
setTabicons(mViewPager1.getCurrentItem());
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
@Override
|
250
|
+
|
251
|
+
public void onGlobalLayout() {
|
252
|
+
|
253
|
+
}
|
46
254
|
|
47
255
|
}
|
48
256
|
|
49
|
-
mViewPager1.setCurrentItem(0);
|
50
|
-
|
51
257
|
```
|
52
258
|
|
53
|
-
|
54
|
-
|
55
|
-
以下の
|
259
|
+
tabFragmentは以下のところだけ修正しました。XMLは変更していません。
|
56
|
-
|
260
|
+
|
57
|
-
```
|
261
|
+
```java
|
262
|
+
|
58
|
-
|
263
|
+
public class tabFragment extends Fragment {
|
264
|
+
|
265
|
+
(省略)
|
266
|
+
|
267
|
+
public static tabFragment newInstance(int tubpos) {
|
268
|
+
|
269
|
+
tabFragment frag = new tabFragment();
|
270
|
+
|
59
|
-
|
271
|
+
Bundle args = new Bundle();
|
60
|
-
|
61
|
-
|
272
|
+
|
62
|
-
|
63
|
-
public void run() {
|
64
|
-
|
65
|
-
|
273
|
+
args.putInt("tabPosition", tubpos);
|
274
|
+
|
66
|
-
|
275
|
+
frag.setArguments(args);
|
276
|
+
|
277
|
+
return frag;
|
278
|
+
|
67
|
-
}
|
279
|
+
}
|
68
|
-
|
69
|
-
}, 100);
|
70
280
|
|
71
281
|
```
|
72
282
|
|
73
283
|
|
74
284
|
|
75
|
-
ま
|
76
|
-
|
77
|
-
m
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
not
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
285
|
+
mainのLayoutを追記します
|
286
|
+
|
287
|
+
```xml
|
288
|
+
|
289
|
+
<?xml version="1.0" encoding="utf-8"?>
|
290
|
+
|
291
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
292
|
+
|
293
|
+
android:id="@+id/relativeLayout"
|
294
|
+
|
295
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
296
|
+
|
297
|
+
xmlns:tools="http://schemas.android.com/tools"
|
298
|
+
|
299
|
+
android:layout_width="match_parent"
|
300
|
+
|
301
|
+
android:layout_height="match_parent"
|
302
|
+
|
303
|
+
android:fitsSystemWindows="true"
|
304
|
+
|
305
|
+
tools:context=".MainActivity">
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
<TextView
|
310
|
+
|
311
|
+
android:layout_width="wrap_content"
|
312
|
+
|
313
|
+
android:layout_height="wrap_content"
|
314
|
+
|
315
|
+
android:text="Hello World!"
|
316
|
+
|
317
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
318
|
+
|
319
|
+
app:layout_constraintLeft_toLeftOf="parent"
|
320
|
+
|
321
|
+
app:layout_constraintRight_toRightOf="parent"
|
322
|
+
|
323
|
+
app:layout_constraintTop_toTopOf="parent" />
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
<android.support.v4.view.ViewPager
|
328
|
+
|
329
|
+
android:id="@+id/container2"
|
330
|
+
|
331
|
+
android:layout_width="match_parent"
|
332
|
+
|
333
|
+
android:layout_height="match_parent"
|
334
|
+
|
335
|
+
android:layout_marginTop="100dp"
|
336
|
+
|
337
|
+
android:layout_marginBottom="55dp"
|
338
|
+
|
339
|
+
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
</android.support.v4.view.ViewPager>
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
<android.support.v4.view.ViewPager
|
348
|
+
|
349
|
+
android:id="@+id/container1"
|
350
|
+
|
351
|
+
android:layout_width="match_parent"
|
352
|
+
|
353
|
+
android:layout_height="match_parent"
|
354
|
+
|
355
|
+
android:layout_marginTop="100dp"
|
356
|
+
|
357
|
+
android:layout_marginBottom="55dp"
|
358
|
+
|
359
|
+
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
</android.support.v4.view.ViewPager>
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
<android.support.design.widget.AppBarLayout
|
368
|
+
|
369
|
+
android:id="@+id/appbar"
|
370
|
+
|
371
|
+
android:layout_width="match_parent"
|
372
|
+
|
373
|
+
android:layout_height="50dp"
|
374
|
+
|
375
|
+
android:background="@color/colorPrimary">
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
<android.support.design.widget.TabLayout
|
380
|
+
|
381
|
+
android:id="@+id/tabs"
|
382
|
+
|
383
|
+
android:layout_width="match_parent"
|
384
|
+
|
385
|
+
android:layout_height="match_parent"
|
386
|
+
|
387
|
+
app:tabMode="scrollable" />
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
</android.support.design.widget.AppBarLayout>
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
<Button
|
396
|
+
|
397
|
+
android:id="@+id/button"
|
398
|
+
|
399
|
+
android:layout_width="wrap_content"
|
400
|
+
|
401
|
+
android:layout_height="wrap_content"
|
402
|
+
|
403
|
+
android:layout_marginTop="50dp"
|
404
|
+
|
405
|
+
android:layout_marginLeft="10dp"
|
406
|
+
|
407
|
+
android:text="Button1"
|
408
|
+
|
409
|
+
android:onClick="button1"/>
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
<Button
|
414
|
+
|
415
|
+
android:id="@+id/button2"
|
416
|
+
|
417
|
+
android:layout_width="wrap_content"
|
418
|
+
|
419
|
+
android:layout_height="wrap_content"
|
420
|
+
|
421
|
+
android:layout_marginTop="50dp"
|
422
|
+
|
423
|
+
android:layout_marginLeft="150dp"
|
424
|
+
|
425
|
+
android:text="Button2"
|
426
|
+
|
427
|
+
android:onClick="button2"/>
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
</RelativeLayout>
|
432
|
+
|
433
|
+
```
|
92
434
|
|
93
435
|
|
94
436
|
|
@@ -123,105 +465,3 @@
|
|
123
465
|
</LinearLayout>
|
124
466
|
|
125
467
|
```
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
SectionsPagerAdapterは以下のような感じです。
|
130
|
-
|
131
|
-
```java
|
132
|
-
|
133
|
-
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
|
134
|
-
|
135
|
-
public SectionsPagerAdapter(FragmentManager fm) {
|
136
|
-
|
137
|
-
super(fm);
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
@Override
|
142
|
-
|
143
|
-
public Fragment getItem(int position) {
|
144
|
-
|
145
|
-
tabFragment npanel1 = tabFragment.newInstance(position);
|
146
|
-
|
147
|
-
return npanel1;
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
@Override
|
152
|
-
|
153
|
-
public int getCount() {
|
154
|
-
|
155
|
-
return 7;
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
@Override
|
160
|
-
|
161
|
-
public CharSequence getPageTitle(int position) {
|
162
|
-
|
163
|
-
return null;
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
@Override
|
168
|
-
|
169
|
-
public Object instantiateItem(ViewGroup container, int position) {
|
170
|
-
|
171
|
-
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
|
172
|
-
|
173
|
-
mTabFragment = (tabFragment) createdFragment;
|
174
|
-
|
175
|
-
return createdFragment;
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
@Override
|
180
|
-
|
181
|
-
public int getItemPosition(Object object) {
|
182
|
-
|
183
|
-
return POSITION_NONE;
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
public void destroyAllItem(ViewPager pager) {
|
188
|
-
|
189
|
-
for (int i = 0; i < getCount() - 1; i++) {
|
190
|
-
|
191
|
-
try {
|
192
|
-
|
193
|
-
Object obj = this.instantiateItem(pager, i);
|
194
|
-
|
195
|
-
if (obj != null) destroyItem(pager, i, obj);
|
196
|
-
|
197
|
-
} catch (Exception e) {
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
@Override
|
206
|
-
|
207
|
-
public void destroyItem(ViewGroup container, int position, Object object) {
|
208
|
-
|
209
|
-
super.destroyItem(container, position, object);
|
210
|
-
|
211
|
-
if (position <= getCount()) {
|
212
|
-
|
213
|
-
FragmentManager manager = ((Fragment) object).getFragmentManager();
|
214
|
-
|
215
|
-
FragmentTransaction trans = manager.beginTransaction();
|
216
|
-
|
217
|
-
trans.remove((Fragment) object);
|
218
|
-
|
219
|
-
trans.commit();
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
```
|
2
SectionsPagerAdapter追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -123,3 +123,105 @@
|
|
123
123
|
</LinearLayout>
|
124
124
|
|
125
125
|
```
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
SectionsPagerAdapterは以下のような感じです。
|
130
|
+
|
131
|
+
```java
|
132
|
+
|
133
|
+
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
|
134
|
+
|
135
|
+
public SectionsPagerAdapter(FragmentManager fm) {
|
136
|
+
|
137
|
+
super(fm);
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
@Override
|
142
|
+
|
143
|
+
public Fragment getItem(int position) {
|
144
|
+
|
145
|
+
tabFragment npanel1 = tabFragment.newInstance(position);
|
146
|
+
|
147
|
+
return npanel1;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
@Override
|
152
|
+
|
153
|
+
public int getCount() {
|
154
|
+
|
155
|
+
return 7;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
@Override
|
160
|
+
|
161
|
+
public CharSequence getPageTitle(int position) {
|
162
|
+
|
163
|
+
return null;
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
@Override
|
168
|
+
|
169
|
+
public Object instantiateItem(ViewGroup container, int position) {
|
170
|
+
|
171
|
+
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
|
172
|
+
|
173
|
+
mTabFragment = (tabFragment) createdFragment;
|
174
|
+
|
175
|
+
return createdFragment;
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
@Override
|
180
|
+
|
181
|
+
public int getItemPosition(Object object) {
|
182
|
+
|
183
|
+
return POSITION_NONE;
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
public void destroyAllItem(ViewPager pager) {
|
188
|
+
|
189
|
+
for (int i = 0; i < getCount() - 1; i++) {
|
190
|
+
|
191
|
+
try {
|
192
|
+
|
193
|
+
Object obj = this.instantiateItem(pager, i);
|
194
|
+
|
195
|
+
if (obj != null) destroyItem(pager, i, obj);
|
196
|
+
|
197
|
+
} catch (Exception e) {
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
@Override
|
206
|
+
|
207
|
+
public void destroyItem(ViewGroup container, int position, Object object) {
|
208
|
+
|
209
|
+
super.destroyItem(container, position, object);
|
210
|
+
|
211
|
+
if (position <= getCount()) {
|
212
|
+
|
213
|
+
FragmentManager manager = ((Fragment) object).getFragmentManager();
|
214
|
+
|
215
|
+
FragmentTransaction trans = manager.beginTransaction();
|
216
|
+
|
217
|
+
trans.remove((Fragment) object);
|
218
|
+
|
219
|
+
trans.commit();
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
```
|
1
customtabを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -89,3 +89,37 @@
|
|
89
89
|
|
90
90
|
|
91
91
|
何か試した方が良い方法などについてご連絡お願いします。
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
customtabを追記します
|
96
|
+
|
97
|
+
```xml
|
98
|
+
|
99
|
+
<?xml version="1.0" encoding="utf-8"?>
|
100
|
+
|
101
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
102
|
+
|
103
|
+
android:layout_width="75dp"
|
104
|
+
|
105
|
+
android:layout_height="match_parent">
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<ImageView
|
110
|
+
|
111
|
+
android:layout_width="match_parent"
|
112
|
+
|
113
|
+
android:layout_height="53dp"
|
114
|
+
|
115
|
+
android:scaleType="fitCenter"
|
116
|
+
|
117
|
+
android:id="@+id/icon"
|
118
|
+
|
119
|
+
android:layout_gravity="center"
|
120
|
+
|
121
|
+
android:gravity="center"/>
|
122
|
+
|
123
|
+
</LinearLayout>
|
124
|
+
|
125
|
+
```
|