Skip to content

Instantly share code, notes, and snippets.

@rivancic
Last active December 15, 2015 16:40
Show Gist options
  • Save rivancic/3e44452ba1ca50770547 to your computer and use it in GitHub Desktop.
Save rivancic/3e44452ba1ca50770547 to your computer and use it in GitHub Desktop.
Android Fragment Factory metnod for passing in arguments
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