it's possible to pass a context variable to a DialogFragment?
i've use this code inside dialog for passing a string:
public static ConfirmDialog newInstance( String f) {
ConfirmDialog d = new ConfirmDialog();
Bundle args = new Bundle();
args.putString("FILE_NAME", f);
d.setArguments(args);
return d;
}
but i don't find any function like putString for passing context. It's possible to do that?
Need to use onAttach method : for dialog Fragment
onAttach(Activity activity) is now deprecated,
use onAttach(Context context) instead
Your
DialogFragment
has a very handy method for getting aContext
instance:Fragment#getActivity()
will return the instance of theActivity
(which is aContext
) that theFragment
is attached to. Use it after the Fragment'sonAttach()
is called. The below chart illustrates theFragment
lifecycle, as you can see, usinggetActivity()
fromonCreate()
toonDestroy()
should be a valid call.For more information, read the
Fragment
documentationuse like this: