Created
April 28, 2016 06:42
-
-
Save pranaypatel512/01dd58d98a91e16ab03950637752382d to your computer and use it in GitHub Desktop.
This method is used for fragment transaction
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
/** | |
* push fragment | |
* | |
* @param fragment fragment | |
* @param animate fragment transition animation | |
* @param shouldAdd add to back stack | |
* @param tag fragment tag | |
*/ | |
public void pushFragments(Fragment fragment, boolean animate, boolean shouldAdd, String tag) { | |
FragmentManager manager = getActivity().getSupportFragmentManager(); | |
FragmentTransaction ft = manager.beginTransaction(); | |
if (animate) { | |
ft.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit); | |
} | |
if (shouldAdd) { | |
ft.replace(R.id.content, fragment, tag); | |
ft.addToBackStack(tag); | |
ft.commitAllowingStateLoss(); | |
} else { | |
manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); | |
ft.replace(R.id.content, fragment, tag); | |
ft.commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment