In this short post I will show [ DialogFragment Android Pass arguments ] you how to dynamically provide arguments to DialogFragment from another Fragment or Activity.
NewInstance -> DialogFragment Android pass arguments
Let’s create static public newInstance method in your code.
static public TestDialogFragment newInstance(String testStringArg) { TestDialogFragment f = new TestDialogFragment(); // Add provided argument to Bundles Bundle args = new Bundle(); args.putString("testStringArgKey", testStringArg); f.setArguments(args); return f; }
And next in the onCreateDialog method just get this argument value like in the code below.
@Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { ... final String testStringArgValue = getArguments().getString("testStringArgKey"); ... }
Finally
Now you can pass arguments from your entry Fragment or Activity.
DialogFragment newFragment = TestDialogFragment.newInstance("BigDataETL is awesome!");
If you enjoyed this post please add the comment below and share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!