Java Code Examples for androidx.fragment.app.FragmentTransaction#commitNow()
The following examples show how to use
androidx.fragment.app.FragmentTransaction#commitNow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentRight.java From Pixiv-Shaft with MIT License | 6 votes |
@Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); if (isVisibleToUser && !isLoad && isAdded()) { FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); FragmentRecmdUserHorizontal recmdUser = new FragmentRecmdUserHorizontal(); transaction.add(R.id.fragment_container, recmdUser, "FragmentRecmdUserHorizontal"); FragmentEvent fragmentFollowIllust = new FragmentEvent(); transaction.add(R.id.fragment_recy, fragmentFollowIllust); transaction.commitNow(); isLoad = true; } }
Example 2
Source File: FragmentNavigator.java From SAI with GNU General Public License v3.0 | 6 votes |
public void switchTo(String tag) { ensureStateWasRestored(); if (mCurrentFragment != null && tag.equals(mCurrentFragment.getTag())) return; FragmentTransaction transaction = mFragmentManager.beginTransaction(); if (mCurrentFragment != null) { transaction.hide(mCurrentFragment); } Fragment newFragment = mFragmentManager.findFragmentByTag(tag); if (newFragment != null) { transaction.show(newFragment); } else { newFragment = mFragmentFactory.createFragment(tag); transaction.add(mContainerId, newFragment, tag); } mCurrentFragment = newFragment; transaction.commitNow(); }
Example 3
Source File: MainActivity.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
@Override public void onParticipatingGame(@NonNull GamePermalink game) { currentGame = game; if (isFinishing() || isDestroyed()) return; inflateNavigation(Layout.ONGOING); synchronized (fragmentsLock) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); ongoingGameFragment = OngoingGameFragment.getInstance(game); addOrReplace(transaction, ongoingGameFragment, Item.ONGOING_GAME); if (pyx.config().gameChatEnabled()) { gameChatFragment = ChatFragment.getGameInstance(game.gid); addOrReplace(transaction, gameChatFragment, Item.GAME_CHAT); } try { transaction.commitNow(); navigation.setSelectedItem(Item.ONGOING_GAME); } catch (IllegalStateException ex) { AnalyticsApplication.crashlyticsLog(ex.getMessage() + " at #onParticipatingGame(GamePermalink)"); } } }
Example 4
Source File: FragmentStack.java From Alligator with MIT License | 6 votes |
public void pop(@NonNull TransitionAnimation animation) { List<Fragment> fragments = getFragments(); int count = fragments.size(); if (count == 0) { throw new IllegalStateException("Can't pop fragment when stack is empty."); } Fragment currentFragment = fragments.get(count - 1); Fragment previousFragment = count > 1 ? fragments.get(count - 2) : null; FragmentTransaction transaction = mFragmentManager.beginTransaction(); if (previousFragment != null) { animation.applyBeforeFragmentTransactionExecuted(transaction, previousFragment, currentFragment); } transaction.remove(currentFragment); if (previousFragment != null) { transaction.attach(previousFragment); } transaction.commitNow(); if (previousFragment != null) { animation.applyAfterFragmentTransactionExecuted(previousFragment, currentFragment); } }
Example 5
Source File: FragmentStack.java From Alligator with MIT License | 6 votes |
public void popUntil(@NonNull Fragment fragment, @NonNull TransitionAnimation animation) { List<Fragment> fragments = getFragments(); int count = fragments.size(); int index = fragments.indexOf(fragment); if (index == -1) { throw new IllegalArgumentException("Fragment is not found."); } if (index == count - 1) { return; // nothing to do } FragmentTransaction transaction = mFragmentManager.beginTransaction(); for (int i = index + 1; i < count; i++) { if (i == count - 1) { animation.applyBeforeFragmentTransactionExecuted(transaction, fragment, fragments.get(i)); } transaction.remove(fragments.get(i)); } transaction.attach(fragment); transaction.commitNow(); animation.applyAfterFragmentTransactionExecuted(fragment, fragments.get(count - 1)); }
Example 6
Source File: FragmentStack.java From Alligator with MIT License | 6 votes |
public void push(@NonNull Fragment fragment, @NonNull TransitionAnimation animation) { Fragment currentFragment = getCurrentFragment(); FragmentTransaction transaction = mFragmentManager.beginTransaction(); if (currentFragment != null) { animation.applyBeforeFragmentTransactionExecuted(transaction, fragment, currentFragment); transaction.detach(currentFragment); } int index = getFragmentCount(); transaction.add(mContainerId, fragment, getFragmentTag(index)); transaction.commitNow(); if (currentFragment != null) { animation.applyAfterFragmentTransactionExecuted(fragment, currentFragment); } }
Example 7
Source File: FragmentStack.java From Alligator with MIT License | 6 votes |
public void replace(@NonNull Fragment fragment, @NonNull TransitionAnimation animation) { Fragment currentFragment = getCurrentFragment(); FragmentTransaction transaction = mFragmentManager.beginTransaction(); if (currentFragment != null) { animation.applyBeforeFragmentTransactionExecuted(transaction, fragment, currentFragment); transaction.remove(currentFragment); } int count = getFragmentCount(); int index = count == 0 ? 0 : count - 1; transaction.add(mContainerId, fragment, getFragmentTag(index)); transaction.commitNow(); if (currentFragment != null) { animation.applyAfterFragmentTransactionExecuted(fragment, currentFragment); } }
Example 8
Source File: FragmentStack.java From Alligator with MIT License | 6 votes |
public void reset(@NonNull Fragment fragment, @NonNull TransitionAnimation animation) { List<Fragment> fragments = getFragments(); int count = fragments.size(); FragmentTransaction transaction = mFragmentManager.beginTransaction(); for (int i = 0; i < count; i++) { if (i == count - 1) { animation.applyBeforeFragmentTransactionExecuted(transaction, fragment, fragments.get(i)); } transaction.remove(fragments.get(i)); } transaction.add(mContainerId, fragment, getFragmentTag(0)); transaction.commitNow(); if (count > 0) { animation.applyAfterFragmentTransactionExecuted(fragment, fragments.get(count - 1)); } }
Example 9
Source File: FragmentSwitcher.java From Alligator with MIT License | 6 votes |
public void switchTo(@NonNull Fragment fragment, @NonNull TransitionAnimation animation) { List<Fragment> fragments = getFragments(); boolean isNewFragment = !fragments.contains(fragment); Fragment currentFragment = getCurrentFragment(); FragmentTransaction transaction = mFragmentManager.beginTransaction(); if (currentFragment != null) { animation.applyBeforeFragmentTransactionExecuted(transaction, fragment, currentFragment); transaction.detach(currentFragment); } if (isNewFragment) { transaction.add(mContainerId, fragment, getFragmentTag(fragments.size())); } else { transaction.attach(fragment); } transaction.commitNow(); if (currentFragment != null) { animation.applyAfterFragmentTransactionExecuted(fragment, currentFragment); } }
Example 10
Source File: MaterialDatePicker.java From material-components-android with Apache License 2.0 | 5 votes |
private void startPickerFragment() { calendar = MaterialCalendar.newInstance( dateSelector, getThemeResId(requireContext()), calendarConstraints); pickerFragment = headerToggleButton.isChecked() ? MaterialTextInputPicker.newInstance(dateSelector, calendarConstraints) : calendar; updateHeader(); FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.mtrl_calendar_frame, pickerFragment); fragmentTransaction.commitNow(); pickerFragment.addOnSelectionChangedListener( new OnSelectionChangedListener<S>() { @Override public void onSelectionChanged(S selection) { updateHeader(); confirmButton.setEnabled(dateSelector.isSelectionComplete()); } @Override void onIncompleteSelectionChanged() { confirmButton.setEnabled(false); } }); }