List of usage examples for android.app FragmentTransaction replace
public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment);
From source file:de.anderdonau.spacetrader.Main.java
public void changeFragment(FRAGMENTS fragment) { hide_keyboard(this); if (fragment == gameState.currentState && currentFragment != null) { // Sometimes this seems to be unset. Try to workaround it. currentFragment.gameState = gameState; if (currentFragment.update()) { return; }/* w ww.j a v a 2 s .c o m*/ } FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); if (fragment == FRAGMENTS.NEW_GAME || fragment == FRAGMENTS.ENCOUNTER) { transaction.hide(mNavigationDrawerFragment); } else { transaction.show(mNavigationDrawerFragment); } Bundle args = new Bundle(); args.putSerializable("gamestate", gameState); switch (fragment) { case AVERAGE_PRICES: currentFragment = new FragmentAveragePrices(); break; case BANK: currentFragment = new FragmentBank(); break; case BUY_CARGO: currentFragment = new FragmentBuyCargo(); break; case BUY_EQUIPMENT: currentFragment = new FragmentBuyEquipment(); break; case BUY_NEW_SHIP: currentFragment = new FragmentBuyNewShip(); break; case COMMANDER_STATUS: currentFragment = new FragmentCommanderStatus(); break; case DUMP: currentFragment = new FragmentDumpCargo(); break; case ENCOUNTER: currentFragment = new FragmentEncounter(); break; case GALACTIC_CHART: currentFragment = new FragmentGalacticChart(); break; case NEW_GAME: currentFragment = new FragmentStartNewGame(); break; case OPTIONS: currentFragment = new FragmentOptions(); break; case PERSONNEL_ROSTER: currentFragment = new FragmentPersonnelRoster(); break; case PLUNDER: currentFragment = new FragmentPlunderCargo(); break; case SELL_CARGO: currentFragment = new FragmentSellCargo(); break; case SELL_EQUIPMENT: currentFragment = new FragmentSellEquipment(); break; case SHIPYARD: currentFragment = new FragmentShipyard(); break; case SHIP_INFO: currentFragment = new FragmentShipInfo(); break; case SHORTCUTS: currentFragment = new FragmentShortcuts(); break; case SHORT_RANGE_CHART: currentFragment = new FragmentShortRangeChart(); break; case SYSTEM_INFORMATION: currentFragment = new FragmentSystemInformation(); break; case VERY_RARE_CHEAT: currentFragment = new FragmentVeryRare(); break; case WARP_SYSTEM_INFORMATION: currentFragment = new FragmentWarpSystemInformation(); break; default: return; } currentFragment.setArguments(args); transaction.replace(R.id.container, currentFragment); transaction.commit(); gameState.currentState = fragment; invalidateOptionsMenu(); }