Last active
December 15, 2015 16:40
-
-
Save rivancic/3e44452ba1ca50770547 to your computer and use it in GitHub Desktop.
Android Fragment Factory metnod for passing in arguments
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
public static final String ARGUMENT_ARG = "ARGUMENT_ARG"; | |
private String argumentValue; | |
/** | |
* Factory method for passing arguments. | |
*/ | |
public static Fragment getFragment(String argumentValue) { | |
Fragment fragment = new Fragment(); | |
Bundle bundle = new Bundle(); | |
bundle.putString(ARGUMENT_ARG, argumentValue); | |
fragment.setArguments(bundle); | |
return fragment; | |
} | |
/** | |
* Parsing arguments. | |
*/ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if (getArguments() != null && getArguments().containsKey(ARGUMENT_ARG)) { | |
argumentValue = getArguments().getString(ARGUMENT_ARG); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment