Created
March 21, 2019 12:50
-
-
Save nickyrabit/4f56f8e10a6efd3bd51972cc3ba59c4e to your computer and use it in GitHub Desktop.
Open a new Fragment by replacing the current one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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