@Test public void testFinishUpdate() { final FragmentManager mockFragmentManager = mock(FragmentManager.class); final FragmentStatePagerAdapter adapter = new Adapter(mockFragmentManager); final FragmentTransaction mockTransaction = mock(FragmentTransaction.class); when(mockFragmentManager.beginTransaction()).thenReturn(mockTransaction); final Fragment mockFragment = mock(Fragment.class); when(mockFragment.getFragmentManager()).thenReturn(mockFragmentManager); adapter.destroyItem(container, 0, mockFragment); adapter.finishUpdate(container); verify(mockTransaction).commitNowAllowingStateLoss(); }
@Override public void finishUpdate(@NonNull final ViewGroup container) { if (pendingTransaction != null) { PagerAdapterHelper.finishUpdate(fragmentManager, pendingTransaction); this.pendingTransaction = null; } }
FragmentStatePagerAdapter extends PagerAdapter { @Override public void finishUpdate(@NonNull final ViewGroup container) { if (pendingTransaction != null) { PagerAdapterHelper.finishUpdate(fragmentManager, pendingTransaction); this.pendingTransaction = null; } } }
FragmentStatePagerAdapter extends PagerAdapter { @Override public void finishUpdate(@NonNull final ViewGroup container) { if (pendingTransaction != null) { PagerAdapterHelper.finishUpdate(fragmentManager, pendingTransaction); this.pendingTransaction = null; } } FragmentStatePagerAdapter(@NonNull final FragmentManager fragmentManager); }
FragmentStatePagerAdapter extends PagerAdapter { @Override public void finishUpdate(@NonNull final ViewGroup container) { if (pendingTransaction != null) { PagerAdapterHelper.finishUpdate(fragmentManager, pendingTransaction); this.pendingTransaction = null; } } FragmentStatePagerAdapter(@NonNull final FragmentManager fragmentManager); @Override void startUpdate(@NonNull final ViewGroup container); @SuppressLint("CommitTransaction") @Override @NonNull Object instantiateItem(@NonNull final ViewGroup container, final int position); long getItemId(final int position); @NonNull abstract Fragment getItem(int position); @Override void setPrimaryItem(@NonNull final ViewGroup container, final int position, @Nullable final Object object); @Nullable Fragment getPrimaryFragment(); @IntRange(from = NO_POSITION) int getPrimaryPosition(); @Override boolean isViewFromObject(@NonNull final View view, @NonNull final Object object); @SuppressLint("CommitTransaction") @Override void destroyItem(@NonNull final ViewGroup container, final int position, @NonNull final Object object); @Override void finishUpdate(@NonNull final ViewGroup container); @Override Parcelable saveState(); @Override void restoreState(@Nullable final Parcelable state, @Nullable final ClassLoader loader); }
FragmentStatePagerAdapter extends PagerAdapter { @Override public void finishUpdate(@NonNull final ViewGroup container) { if (pendingTransaction != null) { PagerAdapterHelper.finishUpdate(fragmentManager, pendingTransaction); this.pendingTransaction = null; } } FragmentStatePagerAdapter(@NonNull final FragmentManager fragmentManager); @Override void startUpdate(@NonNull final ViewGroup container); @SuppressLint("CommitTransaction") @Override @NonNull Object instantiateItem(@NonNull final ViewGroup container, final int position); long getItemId(final int position); @NonNull abstract Fragment getItem(int position); @Override void setPrimaryItem(@NonNull final ViewGroup container, final int position, @Nullable final Object object); @Nullable Fragment getPrimaryFragment(); @IntRange(from = NO_POSITION) int getPrimaryPosition(); @Override boolean isViewFromObject(@NonNull final View view, @NonNull final Object object); @SuppressLint("CommitTransaction") @Override void destroyItem(@NonNull final ViewGroup container, final int position, @NonNull final Object object); @Override void finishUpdate(@NonNull final ViewGroup container); @Override Parcelable saveState(); @Override void restoreState(@Nullable final Parcelable state, @Nullable final ClassLoader loader); static final int NO_POSITION; static final long NO_ID; }