You are currently viewing DialogFragment Android Pass Arguments Or Parameters? – Easy & Quick 1 Min Tutorial!
Photo by Denny Müller on Unsplash
Could You Please Share This Post? I Appreciate It And Thank YOU! :) Have A Nice Day!
4.9
(874)

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!");
Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!

BigData-ETL: image 7YOU MIGHT ALSO LIKE

How useful was this post?

Click on a star to rate it!

Average rating 4.9 / 5. Vote count: 874

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?