當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。