本文整理汇总了Java中android.support.v4.app.FragmentTransaction.commitNow方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.commitNow方法的具体用法?Java FragmentTransaction.commitNow怎么用?Java FragmentTransaction.commitNow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.commitNow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearOldFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@SuppressWarnings("RestrictedApi")
private void clearOldFragment() {
FragmentTransaction transaction = mFragmentManager.beginTransaction();
List<Fragment> fragments = mFragmentManager.getFragments();
if (transaction == null || fragments == null || fragments.size() == 0)
return;
boolean doCommit = false;
for (Fragment fragment : fragments) {
if (fragment != this && fragment != null) {
transaction.remove(fragment);
doCommit = true;
}
}
if (doCommit)
transaction.commitNow();
}
示例2: clearOldFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void clearOldFragment() {
FragmentTransaction transaction = mFragmentManager.beginTransaction();
List<Fragment> fragments = mFragmentManager.getFragments();
if (transaction == null || fragments == null || fragments.size() == 0) {
return;
}
boolean doCommit = false;
for (Fragment fragment : fragments) {
// 清除除自己以外的所有fragments
if (fragment != this && fragment != null) {
transaction.remove(fragment);
doCommit = true;
}
}
if (doCommit) {
transaction.commitNow();
}
}
示例3: pop
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void pop(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);
}
}
示例4: popUntil
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void popUntil(Fragment fragment, 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));
}
示例5: push
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void push(Fragment fragment, 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);
}
}
示例6: replace
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void replace(Fragment fragment, TransitionAnimation animation) {
Fragment currentFragment = getCurrentFragment();
FragmentTransaction transaction = mFragmentManager.beginTransaction();
if (currentFragment != null) {
animation.applyBeforeFragmentTransactionExecuted(transaction, currentFragment, fragment);
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);
}
}
示例7: reset
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void reset(Fragment fragment, 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));
}
}
示例8: switchTo
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void switchTo(Fragment fragment, 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);
}
}
示例9: startFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* Show a fragment.
*
* @param thisFragment Now show fragment, can be null.
* @param thatFragment fragment to display.
* @param stickyStack sticky back stack.
* @param requestCode requestCode.
* @param <T> {@link NoFragment}.
*/
protected final <T extends NoFragment> void startFragment(T thisFragment, T thatFragment,
boolean stickyStack, int requestCode) {
FragmentTransaction fragmentTransaction = mFManager.beginTransaction();
if (thisFragment != null) {
FragmentStackEntity thisStackEntity = mFragmentEntityMap.get(thisFragment);
if (thisStackEntity != null) {
if (thisStackEntity.isSticky) {
thisFragment.onPause();
thisFragment.onStop();
fragmentTransaction.hide(thisFragment);
} else {
fragmentTransaction.remove(thisFragment).commit();
fragmentTransaction.commitNow();
fragmentTransaction = mFManager.beginTransaction();
mFragmentEntityMap.remove(thisFragment);
mFragmentStack.remove(thisFragment);
}
}
}
String fragmentTag = thatFragment.getClass().getSimpleName() + mAtomicInteger.incrementAndGet();
fragmentTransaction.add(fragmentLayoutId(), thatFragment, fragmentTag);
fragmentTransaction.addToBackStack(fragmentTag);
fragmentTransaction.commit();
FragmentStackEntity fragmentStackEntity = new FragmentStackEntity();
fragmentStackEntity.isSticky = stickyStack;
fragmentStackEntity.requestCode = requestCode;
thatFragment.setStackEntity(fragmentStackEntity);
mFragmentEntityMap.put(thatFragment, fragmentStackEntity);
mFragmentStack.add(thatFragment);
}
示例10: loadFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void loadFragment(Fragment fragment, String tag){
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if(tag != null) {
transaction.add(R.id.fragment_main_container, fragment, tag);
}else{
transaction.replace(R.id.fragment_main_container, fragment);
}
transaction.commitNow();
checkTabLayout();
}
示例11: removeToDetachFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private Fragment removeToDetachFragment(StateChange stateChange, Path key) {
Fragment fragment = fragmentManager.findFragmentByTag(key.getFragmentTag());
if(fragment != null && (fragment.isDetached() || fragment.getView() == null)) {
FragmentTransaction fragmentTransaction = beginFragmentTransaction(stateChange);
Fragment.SavedState savedState = fragmentManager.saveFragmentInstanceState(fragment);
fragmentTransaction.remove(fragment);
fragmentTransaction.commitNow();
fragment.setInitialSavedState(savedState);
}
return fragment;
}
示例12: addFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void addFragment(@NonNull Fragment newFragment) {
final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_main, newFragment);
fragmentTransaction.commitNow();
}
示例13: setFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void setFragment(@NonNull Fragment fragment, String tag) {
final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_cards, fragment, tag);
fragmentTransaction.commitNow();
}
示例14: handleStateChange
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void handleStateChange(StateChange stateChange) {
MasterDetailPath topKey = stateChange.topNewState();
Path masterKey;
Path detailKey = NoDetailsPath.create();
if(!topKey.isMaster()) {
detailKey = topKey;
masterKey = topKey.getMaster();
} else {
masterKey = topKey;
}
Fragment masterFragment = removeToDetachFragment(stateChange, masterKey);
Fragment detailFragment = removeToDetachFragment(stateChange, detailKey);
FragmentTransaction fragmentTransaction = beginFragmentTransaction(stateChange);
if(!topKey.isMaster()) {
removeFragment(fragmentTransaction, NoDetailsPath.create());
}
List<Path> previousState = stateChange.getPreviousState();
List<Path> newState = stateChange.getNewState();
for(Path previousKey : previousState) {
if(!newState.contains(previousKey)) {
removeFragment(fragmentTransaction, previousKey);
} else {
if(!previousKey.equals(masterKey) && !previousKey.equals(detailKey)) {
detachFragment(fragmentTransaction, previousKey);
}
}
}
Path previousTop = stateChange.topPreviousState(); // remove outlying master
if(previousTop != null && (previousTop instanceof MasterDetailPath)) {
MasterDetailPath previousMasterDetailTop = (MasterDetailPath) previousTop;
if(!previousMasterDetailTop.isMaster() && !stateChange.getNewState()
.contains(previousMasterDetailTop) && !stateChange.getNewState()
.contains(previousMasterDetailTop.getMaster()) && !stateChange.<MasterDetailPath>topNewState().getMaster()
.equals(previousMasterDetailTop.getMaster())) {
Fragment previousMaster = fragmentManager.findFragmentByTag(previousMasterDetailTop.getMaster().getFragmentTag());
if(previousMaster != null) {
fragmentTransaction.remove(previousMaster);
}
}
}
for(Path newKey : stateChange.<Path>getNewState()) {
if(!newKey.equals(masterKey) && !newKey.equals(detailKey)) {
detachFragment(fragmentTransaction, newKey);
}
}
reattachRemovedFragment(masterFragment, fragmentTransaction, masterKey, masterContainerId);
reattachRemovedFragment(detailFragment, fragmentTransaction, detailKey, detailContainerId);
fragmentTransaction.commitNow();
}
示例15: openEditor
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void openEditor(CustomAnimationBody animationBody) {
final EditorFragment editorFragment = new EditorFragment();
final FragmentManager fragmentManager = getSupportFragmentManager();
editorFragment.setAnimationBody(animationBody);
final FragmentTransaction transaction =
fragmentManager.beginTransaction()
.replace(R.id.editorPanelContainer, editorFragment, EditorFragment.TAG);
binding.mainPanelContainer.setVisibility(View.INVISIBLE);
final Animator showAnimation = getShowWithReveal(binding.editorPanelContainer);
Flubber.with()
.animation(FABRevealProvider.create(R.drawable.ic_done_white_24dp))
.duration(DURATION_REVEAL)
.autoStart(true)
.createFor(binding.floatingActionButton);
showAnimation.start();
transaction.commitNow();
binding.setEditorOpen(true);
}