Skip to content

Instantly share code, notes, and snippets.

@nickyrabit
Created March 21, 2019 12:50
Show Gist options
  • Save nickyrabit/4f56f8e10a6efd3bd51972cc3ba59c4e to your computer and use it in GitHub Desktop.
Save nickyrabit/4f56f8e10a6efd3bd51972cc3ba59c4e to your computer and use it in GitHub Desktop.
Open a new Fragment by replacing the current one
//this is the method
//R.id.frame should be R.id.name_of_your_frame_layout
public void goToFragment(Fragment fragment) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.frame, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
//this is how you use it
gotoFragment(new AnotherFragment());
//Make sure the new fragment has a constructor (well you have to have it anyways)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment