Created
September 23, 2015 09:28
-
-
Save miva2/b8581f8756a99a204502 to your computer and use it in GitHub Desktop.
Snippet of a BaseActivity class extended by child Activities. Makes it simpler to switch fragments in the same Activity if the setup is always the same. Removes repetition.
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
protected void switchToFragment(Fragment fragment) { | |
switchToFragment(fragment, false, null); | |
} | |
protected void switchToFragment(Fragment fragment, boolean addToBackStack, String tag) { | |
if (fragment != null) { | |
FragmentTransaction transaction = getFragmentManager().beginTransaction().replace(R.id.container, fragment); | |
if (addToBackStack) { transaction.addToBackStack(tag); } | |
transaction.commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment