Skip to content

Instantly share code, notes, and snippets.

@wesleyfsmith
Created June 15, 2013 00:07
Show Gist options
  • Select an option

  • Save wesleyfsmith/5786184 to your computer and use it in GitHub Desktop.

Select an option

Save wesleyfsmith/5786184 to your computer and use it in GitHub Desktop.
public void showFragment(ParentFragment fragment, int transition, int containerViewId) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
if (containerViewId == NO_CONTAINER) {
containerViewId = R.id.activity_root;
}
if (currentFragment == null) {
fragmentTransaction.add(containerViewId, fragment);
} else {
fragmentTransaction.replace(containerViewId, fragment);
}
fragmentTransaction.setTransition(transition);
addToBackStack(fragment.getClass().getName(), fragmentTransaction);
fragmentTransaction.commit();
currentFragment = fragment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment