本文整理汇总了Java中android.support.v4.app.FragmentManager.beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentManager.beginTransaction方法的具体用法?Java FragmentManager.beginTransaction怎么用?Java FragmentManager.beginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.FragmentManager
的用法示例。
在下文中一共展示了FragmentManager.beginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initFragment
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
private void initFragment(){
homeMyFragment = HomeMyFragment.newInstance();
homeMyFragment.setOnRefresh(new HomeMyFragment.OnRefresh() {
@Override
public void success() {
pullToRefreshLayout.finishRefresh();
}
@Override
public void error() {
pullToRefreshLayout.finishRefresh();
showToast("加载失败,请重试");
}
});
FragmentManager fm = getChildFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.home_fragment_container, homeMyFragment);
ft.commit();
}
示例2: replaceFragment
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
* 替换碎片
* 为了保证不出现碎片重叠现象,手动禁用控件并延迟启用
* @param fragment
* @param slideType
*/
private void replaceFragment(Fragment fragment, int slideType) {
FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
switch (slideType){
case SLIDE_FROM_LEFT_TO_RIGHT:
transaction.setCustomAnimations(R.anim.slide_left_in,R.anim.slide_right_out);
break;
case SLIDE_FROM_RIGHT_TO_LEFT:
transaction.setCustomAnimations(R.anim.slide_right_in,R.anim.slide_left_out);
break;
}
transaction.replace(R.id.findpwd_main_frame, fragment);
transaction.commit();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {}
}, 200);
}
示例3: changeView
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
private void changeView(int position) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
Fragment fragment = mFragments.get(position);
if (fragment.isAdded()) {
transaction.show(fragment);
} else {
transaction.add(R.id.sticky_container, fragment);
mVisibleFragments.add(fragment);
}
for (Fragment fragment1 : mVisibleFragments) {
if (fragment1 != fragment) {
if (fragment1.isVisible()) {
transaction.hide(fragment1);
transaction.addToBackStack(null);
}
}
}
transaction.commit();
}
示例4: showAlipayDialog
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
@TargetApi(17)
private void showAlipayDialog(boolean notOpenFlag) {
FragmentManager fm = getSupportFragmentManager();
if (fm != null && getActivity() != null && !getActivity().isDestroyed()) {
FragmentTransaction ft = fm.beginTransaction();
this.mAlipayAutoPayDialog = (AlipayAutoPayDialog) fm.findFragmentByTag("showmAlipayPayDialog");
Bundle bundle = new Bundle();
bundle.putBoolean(AlipayConstant.NOT_OPEN_CONTINUE_MONTHLY, notOpenFlag);
bundle.putBoolean(AlipayConstant.IS_MOBILE_VIP_FLAG, this.mIsMobileVipFlag);
if (this.mAlipayAutoPayDialog == null) {
this.mAlipayAutoPayDialog = new AlipayAutoPayDialog();
} else {
ft.remove(this.mAlipayAutoPayDialog);
}
this.mAlipayAutoPayDialog.setAlipayConfirmCallback(this);
if (this.mAlipayAutoPayDialog.getArguments() == null) {
this.mAlipayAutoPayDialog.setArguments(bundle);
}
ft.add(this.mAlipayAutoPayDialog, "showmAlipayPayDialog");
ft.commitAllowingStateLoss();
}
}
示例5: createTransaction
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
private FragmentTransaction createTransaction(@NonNull FragmentManager fragmentManager) {
if (parameters != null && !parameters.isEmpty()) {
fragment.setArguments(parameters);
}
FragmentTransaction transaction = fragmentManager.beginTransaction();
if (addToBackStack) {
transaction.addToBackStack(fragment.getClass().getSimpleName());
}
if (!sharedElement.isEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
for (View element : sharedElement) {
transaction.addSharedElement(element, element.getTransitionName());
}
}
if (animation != null) {
transaction.setCustomAnimations(animation.getEnter(),
animation.getExit(),
animation.getPopEnter(),
animation.getPopExit());
}
return transaction;
}
示例6: addFragmentToActivity
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
public static void addFragmentToActivity (FragmentManager fragmentManager,
Fragment fragment,
int frameId,
String tag) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(frameId, fragment, tag);
transaction.commit();
}
示例7: addFragmentToActivity
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
* The {@code fragment} is added to the container view with id {@code frameId}. The operation is
* performed by the {@code fragmentManager}.
*
*/
public static void addFragmentToActivity (FragmentManager fragmentManager,
Fragment fragment,
int frameId,
String tag) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(frameId, fragment, tag);
transaction.commit();
}
示例8: addFragmentToActivity
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
* The {@code fragment} is added to the container view with id {@code frameId}. The operation is
* performed by the {@code fragmentManager}.
*
*/
public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager,
@NonNull Fragment fragment, int frameId) {
checkNotNull(fragmentManager);
checkNotNull(fragment);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(frameId, fragment);
transaction.commit();
}
示例9: replaceFragment
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
* 替换碎片
* 为了保证不出现碎片重叠现象,手动禁用控件并延迟启用
* @param fragment
* @param slideType
*/
private void replaceFragment(Fragment fragment, int slideType) {
navigationView.setAllButtonEnabled(false);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
switch (slideType){
case SLIDE_FROM_LEFT_TO_RIGHT:
transaction.setCustomAnimations(R.anim.slide_left_in,R.anim.slide_right_out);
break;
case SLIDE_FROM_RIGHT_TO_LEFT:
transaction.setCustomAnimations(R.anim.slide_right_in,R.anim.slide_left_out);
break;
}
transaction.replace(R.id.main_frame, fragment);
transaction.commit();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
navigationView.setAllButtonEnabled(true);
}
}, 200);
}
示例10: dismissDialog
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
public static void dismissDialog(FragmentManager manager) {
FragmentTransaction ft = manager.beginTransaction();
Fragment fragment = manager.findFragmentByTag("dialog");
if (fragment != null) {
ft.remove(fragment).commit();
}
}
示例11: addFragmentToActivityWithSharedElement
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
public static void addFragmentToActivityWithSharedElement(
@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId, String tag,
int enterAnimation, int exitAnimation, int popEnter, int popExit, View sharedElement,
String transitionName) {
checkNotNull(fragmentManager);
checkNotNull(fragment);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(enterAnimation, exitAnimation, popEnter, popExit);
fragmentTransaction.addSharedElement(sharedElement, transitionName);
fragmentTransaction.replace(frameId, fragment, tag);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commitAllowingStateLoss();
}
示例12: show
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
public void show(FragmentManager fragmentManager, String tag) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
Fragment prevFragment = fragmentManager.findFragmentByTag(tag);
if (prevFragment != null) {
transaction.remove(prevFragment);
}
transaction.addToBackStack(null);
show(transaction, tag);
}
示例13: changeChildrenPresence
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
private void changeChildrenPresence(boolean isPresented) {
FragmentManager childFragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = childFragmentManager.beginTransaction();
Fragment child1 = childFragmentManager.findFragmentById(R.id.childContainer1);
Fragment child2 = childFragmentManager.findFragmentById(R.id.childContainer2);
if (isPresented) {
// Add children if they aren't presented
if (child1 == null) {
fragmentTransaction.add(R.id.childContainer1, new ChildFragment());
}
if (child2 == null) {
fragmentTransaction.add(R.id.childContainer2, new ChildFragment());
}
} else {
// Remove children if they are presented
if (child1 != null) {
fragmentTransaction.remove(child1);
}
if (child2 != null) {
fragmentTransaction.remove(child2);
}
}
fragmentTransaction.commit();
}
示例14: onCreate
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Fragment fragment = new MmsPreferencesFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(android.R.id.content, fragment);
fragmentTransaction.commit();
}
示例15: addFragmentToActivity
import android.support.v4.app.FragmentManager; //导入方法依赖的package包/类
/**
* The {@code fragment} is added to the container view with id {@code frameId}. The operation is
* performed by the {@code fragmentManager}.
*
*/
public static void addFragmentToActivity (@NonNull FragmentManager fragmentManager,
@NonNull Fragment fragment, int frameId) {
checkNotNull(fragmentManager);
checkNotNull(fragment);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(frameId, fragment);
transaction.commit();
}