Skip to content

Instantly share code, notes, and snippets.

@magicgoose
Created May 27, 2015 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magicgoose/a6199da552d5abc33b8e to your computer and use it in GitHub Desktop.
Save magicgoose/a6199da552d5abc33b8e to your computer and use it in GitHub Desktop.
private void switchPage(final Class<? extends Fragment> fragmentClass) throws IllegalAccessException, InstantiationException {
final FragmentManager fm = getSupportFragmentManager();
final Fragment existingFragment = fm.findFragmentById(FragmentsID);
if (existingFragment != null && existingFragment.getClass().equals(fragmentClass))
return;
final Fragment newFragment = fragmentClass.newInstance();
final FragmentTransaction ft = fm.beginTransaction();
if (existingFragment != null) {
ft.replace(FragmentsID, newFragment);
} else {
ft.add(FragmentsID, newFragment);
}
ft.commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment