質問編集履歴

3

クラス名の追加

2016/05/22 09:27

投稿

ken0625
ken0625

スコア40

test CHANGED
File without changes
test CHANGED
@@ -174,6 +174,8 @@
174
174
 
175
175
  ```ここに言語を入力
176
176
 
177
+ public abstract class ArrayFragmentStatePagerAdapter<T> extends ArrayPagerAdapter<T> {
178
+
177
179
  private static final String TAG = "StatePagerAdapter";
178
180
 
179
181
  private static final boolean DEBUG = false;
@@ -270,6 +272,10 @@
270
272
 
271
273
  }
272
274
 
275
+ }
276
+
277
+
278
+
273
279
  ```
274
280
 
275
281
 
@@ -278,6 +284,8 @@
278
284
 
279
285
  ```ここに言語を入力
280
286
 
287
+ public abstract class ArrayPagerAdapter<T> extends PagerAdapter {
288
+
281
289
  @Override
282
290
 
283
291
  public Object instantiateItem(ViewGroup container, int position) {
@@ -324,6 +332,8 @@
324
332
 
325
333
  */
326
334
 
335
+ }
336
+
327
337
  ```
328
338
 
329
339
 

2

ソースの追加

2016/05/22 09:26

投稿

ken0625
ken0625

スコア40

test CHANGED
File without changes
test CHANGED
@@ -271,3 +271,151 @@
271
271
  }
272
272
 
273
273
  ```
274
+
275
+
276
+
277
+ これが上のスーパーメソッドです
278
+
279
+ ```ここに言語を入力
280
+
281
+ @Override
282
+
283
+ public Object instantiateItem(ViewGroup container, int position) {
284
+
285
+ return items.get(position);
286
+
287
+ }
288
+
289
+
290
+
291
+ /**
292
+
293
+ * Adds the specified item at the end of the array.
294
+
295
+ *
296
+
297
+ * @param item The item to add at the end of the array.
298
+
299
+ */
300
+
301
+ public void add(T item) {
302
+
303
+ synchronized (lock) {
304
+
305
+ items.add(identifiedItemFactory.create(item));
306
+
307
+ }
308
+
309
+ itemPositionChangeChecked = new SparseBooleanArray(this.items.size());
310
+
311
+ notifyDataSetChanged();
312
+
313
+ }
314
+
315
+
316
+
317
+ /**
318
+
319
+ * Adds the specified items at the end of the array.
320
+
321
+ *
322
+
323
+ * @param items The items to add at the end of the array.
324
+
325
+ */
326
+
327
+ ```
328
+
329
+
330
+
331
+ うえで使われているクラスです
332
+
333
+ ```ここに言語を入力
334
+
335
+
336
+
337
+ static class IdentifiedItemFactory<T> {
338
+
339
+ private long lastId;
340
+
341
+
342
+
343
+ IdentifiedItemFactory(long firstId) {
344
+
345
+ lastId = firstId;
346
+
347
+ }
348
+
349
+
350
+
351
+ IdentifiedItem<T> create(T item) {
352
+
353
+ return new IdentifiedItem(lastId++, item);
354
+
355
+ }
356
+
357
+
358
+
359
+ ArrayList<IdentifiedItem<T>> createList(List<T> items) {
360
+
361
+ ArrayList<IdentifiedItem<T>> list = new ArrayList();
362
+
363
+ for (T item : items) {
364
+
365
+ list.add(create(item));
366
+
367
+ }
368
+
369
+ return list;
370
+
371
+ }
372
+
373
+
374
+
375
+ @SafeVarargs
376
+
377
+ final ArrayList createList(T... items) {
378
+
379
+ return createList(new ArrayList<>(Arrays.asList(items)));
380
+
381
+ }
382
+
383
+ }
384
+
385
+
386
+
387
+ static class IdentifiedItem<T> {
388
+
389
+ long id;
390
+
391
+ T item;
392
+
393
+
394
+
395
+ public IdentifiedItem(long id, T item) {
396
+
397
+ this.id = id;
398
+
399
+ this.item = item;
400
+
401
+ }
402
+
403
+
404
+
405
+ @Override
406
+
407
+ public String toString() {
408
+
409
+ return "IdentifiedItem{" +
410
+
411
+ "id=" + id +
412
+
413
+ ", item=" + item +
414
+
415
+ '}';
416
+
417
+ }
418
+
419
+ }
420
+
421
+ ```

1

ソースコードの追加

2016/05/22 08:27

投稿

ken0625
ken0625

スコア40

test CHANGED
File without changes
test CHANGED
@@ -169,3 +169,105 @@
169
169
 
170
170
 
171
171
  ```
172
+
173
+ adapterが継承してるメソッドです
174
+
175
+ ```ここに言語を入力
176
+
177
+ private static final String TAG = "StatePagerAdapter";
178
+
179
+ private static final boolean DEBUG = false;
180
+
181
+
182
+
183
+ private final FragmentManager mFragmentManager;
184
+
185
+ private FragmentTransaction mCurTransaction = null;
186
+
187
+ private ItemsStateHandler mItemsStateHandler;
188
+
189
+ private ArrayList<Fragment.SavedState> mSavedState = new ArrayList<>();
190
+
191
+
192
+
193
+ private ArrayList<Fragment> mFragments = new ArrayList<>();
194
+
195
+ private Fragment mCurrentPrimaryItem = null;
196
+
197
+
198
+
199
+ @SuppressLint("CommitTransaction")
200
+
201
+ @Override
202
+
203
+ public Object instantiateItem(ViewGroup container, int position) {
204
+
205
+ // If we already have this item instantiated, there is nothing
206
+
207
+ // to do. This can happen when we are restoring the entire pager
208
+
209
+ // from its saved state, where the fragment manager has already
210
+
211
+ // taken care of restoring the fragments we previously had instantiated.
212
+
213
+ if (mFragments.size() > position) {
214
+
215
+ Fragment f = mFragments.get(position);
216
+
217
+ if (f != null) {
218
+
219
+
220
+
221
+ return super.instantiateItem(container, position);
222
+
223
+ }
224
+
225
+ }
226
+
227
+
228
+
229
+ if (mCurTransaction == null) {
230
+
231
+ mCurTransaction = mFragmentManager.beginTransaction();
232
+
233
+ }
234
+
235
+
236
+
237
+ Fragment fragment = getFragment(getItem(position), position);
238
+
239
+ if (DEBUG) Log.d(TAG, "Adding item #" + position + ": f=" + fragment);
240
+
241
+ if (mSavedState.size() > position) {
242
+
243
+ Fragment.SavedState fss = mSavedState.get(position);
244
+
245
+ if (fss != null) {
246
+
247
+ fragment.setInitialSavedState(fss);
248
+
249
+ }
250
+
251
+ }
252
+
253
+ while (mFragments.size() <= position) {
254
+
255
+ mFragments.add(null);
256
+
257
+ }
258
+
259
+ fragment.setMenuVisibility(false);
260
+
261
+ fragment.setUserVisibleHint(false);
262
+
263
+ mFragments.set(position, fragment);
264
+
265
+ mCurTransaction.add(container.getId(), fragment);
266
+
267
+
268
+
269
+ return super.instantiateItem(container, position);
270
+
271
+ }
272
+
273
+ ```