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


Java FragmentTransaction.addToBackStack方法代码示例

本文整理汇总了Java中android.support.v4.app.FragmentTransaction.addToBackStack方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.addToBackStack方法的具体用法?Java FragmentTransaction.addToBackStack怎么用?Java FragmentTransaction.addToBackStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.FragmentTransaction的用法示例。


在下文中一共展示了FragmentTransaction.addToBackStack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addFragment

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void addFragment(Fragment fragment, int fragmentPosition, boolean addToBackStack) {

        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        // FIXME: Because we have no tagging system we need to use the int as mContext
        // tag, which may cause collisions
        ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
        ft.add(fragmentPosition, fragment, String.valueOf(fragmentPosition));
        // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        if (addToBackStack) {
            ft.addToBackStack(null);
        }
        ft.commit();
    }
 
开发者ID:victordiaz,项目名称:phonk,代码行数:14,代码来源:BaseActivity.java

示例2: replaceOneFragment

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
 * 替换当前Fragment里的某个FrameLayout布局
 *
 * @param resId       被替换的布局ID
 * @param fragmentTab 新的Fragment名
 * @param arguments   传入新的Fragment的Bundle
 * @param isAddToBack 是否加入回退栈
 */
private void replaceOneFragment(@IdRes int resId, String fragmentTab, Bundle arguments, boolean isAddToBack) {
    int childrenFragmentContainerResID = ((BasicFragment) mCurrentFragment).getChildrenFragmentContainerResID();
    int layoutId = resId <= 0 ? childrenFragmentContainerResID : resId;

    if (layoutId == -1) {
        throw new IllegalStateException("You should overwrite getChildrenFragmentContainerResID from BasicFragment");
    }

    FragmentManager manager = mCurrentFragment.getChildFragmentManager();
    if (manager != null) {
        FragmentTransaction transaction = manager.beginTransaction();

        transaction
                .setCustomAnimations(R.anim.right_enter, R.anim.left_exit, R.anim.left_enter, R.anim.right_exit)
                .replace(layoutId, fragmentProvider(fragmentTab, arguments), fragmentTab);
        if (isAddToBack) {
            transaction.addToBackStack(fragmentTab);
        }

        transaction.commitAllowingStateLoss();

        mLastFragmentName = mCurrentFragment.getClass().getSimpleName();
    }
}
 
开发者ID:Sugarya,项目名称:Closet,代码行数:33,代码来源:BasicActivity.java

示例3: replaceTransaction

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
 * replace事务, 主要用于子Fragment之间的replace
 */
void replaceTransaction(FragmentManager fragmentManager, int containerId, SupportFragment to, boolean addToBack) {
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null) return;

    checkNotNull(to, "toFragment == null");
    bindContainerId(containerId, to);
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(containerId, to, to.getClass().getName());
    if (addToBack) {
        ft.addToBackStack(to.getClass().getName());
    }
    Bundle bundle = to.getArguments();
    bundle.putBoolean(FRAGMENTATION_ARG_IS_ROOT, true);
    supportCommit(fragmentManager, ft);
}
 
开发者ID:LonelyMushroom,项目名称:aarLibrary,代码行数:19,代码来源:FragmentationDelegate.java

示例4: replaceFragment

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void replaceFragment(Fragment fragment, @Nullable String tag) {
    final String backStateName = fragment.getClass().getName();
    final FragmentManager manager = getSupportFragmentManager();
    boolean fragmentPopped = manager.popBackStackImmediate(backStateName, 0);

    if (!fragmentPopped) {
        //fragment not in back stack, create it.
        Log.d(TAG, "Starting fragment: " + backStateName);
        FragmentTransaction ft = manager.beginTransaction();
        ft.replace(android.R.id.content, fragment, tag);
        ft.addToBackStack(backStateName);
        ft.commit();
    } else {
        Log.d(TAG, "Fragment popped back");
    }
}
 
开发者ID:Adyen,项目名称:adyen-android,代码行数:17,代码来源:CheckoutActivity.java

示例5: showHideFragment

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public static void showHideFragment(FragmentManager manager, Fragment show, Fragment hide, boolean animation, boolean backStack) {
    FragmentTransaction transaction = manager.beginTransaction();
    if (animation) {
        transaction.setCustomAnimations(
                R.anim .fragment_translate_in, R.anim.fragment_translate_out
        ,R.anim.fragment_pop_in,R.anim.fragment_pop_out);
    }
    transaction.show(show);
    if (hide == null) {
        List<Fragment> fragments = manager.getFragments();
        if (fragments != null) {
            for (Fragment fragment : fragments) {
                if (fragment != show) {
                    transaction.hide(fragment);
                }
            }
        }
    } else {
        transaction.hide(hide);
    }
    if (backStack) {
        transaction.addToBackStack("showHideFragment");
    }
    transaction.commit();
}
 
开发者ID:bigjelly,项目名称:ShaddockVideoPlayer,代码行数:26,代码来源:FragmentUtils.java

示例6: replaceFragment

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void replaceFragment(Fragment f, String tag, boolean executeSynchronously, boolean isAddToBackStack) {
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fragment_container, f);
    if (isAddToBackStack) {
        fragmentTransaction.addToBackStack(tag);
    }
    fragmentTransaction.commit();
    if (executeSynchronously) getSupportFragmentManager().executePendingTransactions();
}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:10,代码来源:BaseFragmentActivity.java

示例7: showFragment

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showFragment() {
    Fragment fragment = null;
    if (currentFragment == -1) {
        fragment = OverviewFragment.newInstance();
        currentFragment = MENU_OVERVIEW;
    } else {
        switch (currentFragment) {
            case MENU_OVERVIEW:
                getSupportActionBar().setTitle(R.string.overview);
                fragment = OverviewFragment.newInstance();
                break;
            case MENU_BOOKMARKS:
                getSupportActionBar().setTitle(R.string.bookmarks);
                fragment = BookmarksFragment.newInstance();
                break;
            case MENU_NOTIFICATIONS:
                getSupportActionBar().setTitle(R.string.notifications);
                fragment = NotificationsFragment.newInstance();
                break;
            case MENU_HOSTS:
                getSupportActionBar().setTitle(R.string.hosts);
                fragment = MainHostsFragment.newInstance();
                break;
            case MENU_ABOUT:
                getSupportActionBar().setTitle(R.string.about_program);
                fragment = AboutFragment.newInstance();
                break;
        }
    }

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.content_frame, fragment, getFragmentTag(currentFragment));
    transaction.addToBackStack(null);
    transaction.commit();
}
 
开发者ID:CactusSoft,项目名称:zabbkit-android,代码行数:36,代码来源:SlideMenuActivity.java

示例8: onListFragmentInteraction

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void onListFragmentInteraction(String address) {
    mCurrentFragment = DeviceFragment.newInstance(address);
    FragmentTransaction transaction = mFragmentManager.beginTransaction();
    transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
    transaction.replace(R.id.container, mCurrentFragment);
    transaction.addToBackStack(null);
    transaction.commit();
}
 
开发者ID:martindisch,项目名称:SensorTag-Accelerometer,代码行数:10,代码来源:MainActivity.java

示例9: showDialog

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showDialog(final DialogFragment dialog, final String nameOfFragment) {
    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    final Fragment prev = getSupportFragmentManager().findFragmentByTag(nameOfFragment);
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    dialog.show(ft, nameOfFragment);
}
 
开发者ID:videgro,项目名称:Ships,代码行数:10,代码来源:OpenDeviceActivity.java

示例10: showFragmentByAdd

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showFragmentByAdd(Fragment fragment, boolean addToBackStack){
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (mCurrentFragment != null) {
        fragmentTransaction.remove(mCurrentFragment);
        mCurrentFragment = null;
    }
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.add(R.id.content_container,fragment).commit();
    mCurrentFragment = fragment;
}
 
开发者ID:halohoop,项目名称:AndroidDigIn,代码行数:13,代码来源:MDMainActivity.java

示例11: changeFragment

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
 * Change the current displayed fragment by a new one.
 * - if the fragment is in backstack, it will pop it
 * - if the fragment is already displayed (trying to change the fragment with the same), it will not do anything
 *
 * @param frag            the new fragment to display
 * @param saveInBackstack if we want the fragment to be in backstack
 * @param animate         if we want a nice animation or not
 */
private void changeFragment(Fragment frag, boolean saveInBackstack, boolean animate, String tag) {
    try {
        FragmentManager manager = getSupportFragmentManager();
        boolean fragmentPopped = manager.popBackStackImmediate(tag, 0);

        if (!fragmentPopped && manager.findFragmentByTag(tag) == null) {
            //fragment not in back stack, create it.
            FragmentTransaction transaction = manager.beginTransaction();

            if (animate) {
                Log.d(HomeActivity.class.getName(), "Change Fragment: animate");
                //transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right);
                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            }

            transaction.replace(R.id.fragment_container, frag, tag);

            if (saveInBackstack) {
                Log.d(HomeActivity.class.getName(), "Change Fragment: addToBackTack " + tag);
                transaction.addToBackStack(tag);
            } else {
                Log.d(HomeActivity.class.getName(), "Change Fragment: NO addToBackTack");
            }
            transaction.commit();
        } else {
            // custom effect if fragment is already instanciated
        }
    } catch (IllegalStateException exception) {
        Log.w(HomeActivity.class.getName(), "Unable to commit fragment, could be activity as been killed in background. " + exception.toString());
    }
}
 
开发者ID:JonathandelaSen,项目名称:TheMovies,代码行数:41,代码来源:HomeActivity.java

示例12: showAbout

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void showAbout() {
	popBackStackFull();

    FragmentTransaction ft;
    ft = fm.beginTransaction();
    
    ft.replace(R.id.fragment_content, new RMBTAboutFragment(), AppConstants.PAGE_TITLE_ABOUT);
    ft.addToBackStack(AppConstants.PAGE_TITLE_ABOUT);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);        	
    
    ft.commit();
    refreshActionBar(AppConstants.PAGE_TITLE_ABOUT);
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:14,代码来源:RMBTMainActivity.java

示例13: loadMenu

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void loadMenu() {
    // Create new fragment and transaction
    Fragment newFragment = new RecyclerViewFragment();
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    // Replace whatever is in the fragment_container view with this fragment,
    // and add the transaction to the back stack
    transaction.replace(R.id.fragment_container, newFragment);
    transaction.addToBackStack(null);

    // Commit the transaction
    transaction.commit();
}
 
开发者ID:googlecodelabs,项目名称:admob-native-advanced-feed,代码行数:14,代码来源:MainActivity.java

示例14: showFragment

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
 * Utility method to display a specific Fragment. If the tag is not null we add a backstack
 *
 * @param fragment The Fragment to add
 */
private void showFragment(ShowcaseFragment fragment) {
  final FragmentTransaction fragmentTransaction = getSupportFragmentManager()
      .beginTransaction()
      .replace(R.id.content_main, (Fragment) fragment);
  if (fragment.getBackstackTag() != null) {
    fragmentTransaction.addToBackStack(fragment.getBackstackTag());
  }
  fragmentTransaction.commit();

  setTitle(fragment.getTitleId());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:MainActivity.java

示例15: loadCreateGroup

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void loadCreateGroup() {
    isInCreateGroup = true;
    FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.anim.anim_fragment_enter_from_right,
        R.anim.anim_fragment_exit_to_left, R.anim.anim_fragment_enter_from_left,
        R.anim.anim_fragment_exit_to_right);
    transaction.hide(this);
    transaction.add(R.id.container_set_up, createGroupFragment);
    transaction.addToBackStack("");
    transaction.commit();
}
 
开发者ID:WGPlaner,项目名称:wg_planer,代码行数:12,代码来源:DescriptionFragment.java


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