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?
you can set your args. class IntervModifFragment : DialogFragment(), ModContract. View { companion object { fun newInstance( plom:String,type:String,position: Int):IntervModifFragment { val fragment =IntervModifFragment() val args = Bundle() args. putString( "1",plom) args.
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
Show activity on this post. tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.
Your DialogFragment
has a very handy method for getting a Context
instance:
getActivity()
Fragment#getActivity()
will return the instance of the Activity
(which is a Context
) that the Fragment
is attached to. Use it after the Fragment's onAttach()
is called. The below chart illustrates the Fragment
lifecycle, as you can see, using getActivity()
from onCreate()
to onDestroy()
should be a valid call.
For more information, read the Fragment
documentation
@Override public void onAttach(Activity activity) { // TODO Auto-generated method stub super.onAttach(activity); context=activity; }
Need to use onAttach method : for dialog Fragment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With