Example #1
0
 private void changePage(int position, SliderItem item) {
   mIgnoreBackStack = true;
   if (mCurrentPage >= 0) {
     final SliderItem lastItem = mAdapter.getItem(mCurrentPage);
     final WeakReference<Fragment> ref = lastItem.mLastFragment;
     final Fragment fragment = ref == null ? null : ref.get();
     if (fragment != null && fragment.isAdded() && lastItem.mSaveState) {
       if (!fragment.isDetached()) {
         mFragmentManager.beginTransaction().detach(fragment).commit();
         mFragmentManager.executePendingTransactions();
       }
       lastItem.mSavedState = mFragmentManager.saveFragmentInstanceState(fragment);
     }
   }
   mCurrentPage = position;
   mAdapter.notifyDataSetInvalidated();
   while (mFragmentManager.popBackStackImmediate()) {}
   final Fragment fragment = Fragment.instantiate(item.mFragmentClass);
   if (item.mSavedState != null) {
     fragment.setInitialSavedState(item.mSavedState);
   }
   item.mLastFragment = new WeakReference<Fragment>(fragment);
   replaceFragment(mFragmentManager, fragment);
   mIgnoreBackStack = false;
 }
Example #2
0
 public void onClick(View view) {
   FragmentManager fm = getSupportFragmentManager();
   while (fm.popBackStackImmediate()) {
     fm.executePendingTransactions();
   }
   replaceFragment(Fragment.instantiate(clazz));
   fm.executePendingTransactions();
   postDelayed(
       new Runnable() {
         @Override
         public void run() {
           requireSlidingMenu().showContent();
         }
       },
       100);
 }