I do have a FragmentActivity which contains a Fragment list (with methods to navigate between them). In one of those fragments I need to call a DialogFragment to display a "zoom" on a Picture contained in that fragment.
But it seems that you can't call a DialogFragment directly from a Fragment.
Is there any way to get some kind of "callback" to the FragmentActivity to make this display the DialogFragment over the fragment.
Or simply a "glitch" to call it directly from the Fragment.
If that is the case what are my options?
use getActivity() method. Which will return the enclosing activity for the fragment.
If you want to use Fragments in an app targeting a platform version prior to HoneyComb, you need to add the Support Package to your project and use the FragmentActivity to hold your Fragments . The FragmentActivity class has an API for dealing with Fragments , whereas the Activity class, prior to HoneyComb, doesn't.
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.
When you create a new Dialog
, you can simply call it using this (very) simple method from a Fragment
.
DialogFragment dialog = DialogFragment.instantiate(getActivity(), "Hello world"); dialog.show(getFragmentManager(), "dialog");
If you want to use your own dialog, please use that kind of code.
public class MyDialogFragment extends DialogFragment { //private View pic; public MyDialogFragment() { } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_my_dialog, new LinearLayout(getActivity()), false); // Retrieve layout elements TextView title = (TextView) view.findViewById(R.id.text_title); // Set values title.setText("Not perfect yet"); // Build dialog Dialog builder = new Dialog(getActivity()); builder.requestWindowFeature(Window.FEATURE_NO_TITLE); builder.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); builder.setContentView(view); return builder; } }
it will help if you need to show a fragment dialog inside a fragment
public class DialogBoxFragment extends DialogFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View rootView = inflater.inflate(R.layout.dialog_fragment, container, false); getDialog().setTitle("simple dialog"); return rootView; } }
DialogFragment dialogFragment = new DialogFragment (); dialogFragment.show(getActivity().getFragmentManager(),"simple dialog");
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