当前位置: 首页>>代码示例>>Java>>正文


Java FragmentTransaction.commitNow方法代码示例

本文整理汇总了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();
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:17,代码来源:NavFragment.java

示例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();
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:19,代码来源:NavFragment.java

示例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);
	}
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:24,代码来源:FragmentStack.java

示例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));
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:26,代码来源:FragmentStack.java

示例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);
	}
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:18,代码来源:FragmentStack.java

示例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);
	}
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:19,代码来源:FragmentStack.java

示例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));
	}
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:20,代码来源:FragmentStack.java

示例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);
	}
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:23,代码来源:FragmentSwitcher.java

示例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);
}
 
开发者ID:yanzhenjie,项目名称:NoFragment,代码行数:44,代码来源:CompatActivity.java

示例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();
    }
 
开发者ID:victoraldir,项目名称:BuddyBook,代码行数:14,代码来源:MainActivity.java

示例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;
}
 
开发者ID:Zhuinden,项目名称:simple-stack,代码行数:12,代码来源:MasterDetailFragmentStateChanger.java

示例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();
}
 
开发者ID:GrenderG,项目名称:Protestr,代码行数:7,代码来源:MainActivity.java

示例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();
}
 
开发者ID:owniz,项目名称:OzComicReader,代码行数:7,代码来源:MainActivity.java

示例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();
}
 
开发者ID:Zhuinden,项目名称:simple-stack,代码行数:57,代码来源:MasterDetailFragmentStateChanger.java

示例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);
    }
 
开发者ID:Appolica,项目名称:Flubber,代码行数:28,代码来源:MainActivity.java


注:本文中的android.support.v4.app.FragmentTransaction.commitNow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。