Code example for FragmentTransaction

Methods: addToBackStack, commit, hide, show

1
 
		final FragmentManager manager = getSupportFragmentManager();
		final FragmentTransaction transaction = manager.beginTransaction();
 
		// replace hide current fragment and show selected fragment 
		transaction.hide(fragments[currentFragment]);
		transaction.show(fragments[nextFragment]);
		transaction.addToBackStack(null);
		transaction.commit();
	} 
 
	private void initializeFragments(final FragmentManager fm) {
 
		fragments[MenuButtonsFragment.FragmentIds.MENU_BUTTONS_FRAGMENT] = fm
				.findFragmentById(R.id.menu_buttons_fragment);
		// fragments[MenuButtonsFragment.FragmentIds.MENU_OPTIONS_FRAGMENT] = fm 
		// .findFragmentById(R.id.menu_options_fragment); 
		fragments[MenuButtonsFragment.FragmentIds.MENU_HIGHSCORES_FRAGMENT] = fm
				.findFragmentById(R.id.menu_highscores_fragment);
 
		MenuButtonsFragment.setNavigationListener(this);