-1

I'm trying to create Custom AlertDialog that gives me the full details of an item in listview when it clicks, but when I inflate the layout it won't give me proper measurements of the layouts I have created here's what I mean:

how I want it to be seen:

how it appear with onCreateDialog

Listener

Sizes of layouts in the XML code

Devil10
  • 1,853
  • 1
  • 18
  • 22

1 Answers1

0

For inflating your dialog to the full view you must add this code to the onActivityCreated() or can be done it onCreate Dialog() but after dialog creation. So it is would be efficient to use this in onActivityCreated() method

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    return dialog;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(getLayoutId(), container, false);
}



@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Dialog dialog = getDialog();
    if (dialog != null) {
            dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        }
    }
}

Hoe this will help you.

Devil10
  • 1,853
  • 1
  • 18
  • 22
  • tried both ways still the same problem, i think the problem is that i doesn't inflate the view with the proper measurements – Senlers Kri Apr 18 '18 at 15:03
  • I have edited my answer and add full code to the dialog fragment. Hope this will help you and if not helping then add a frame layout with match parent attributes to your XML code root and then retry it. – Devil10 Apr 18 '18 at 15:10
  • Still not working where do you want me to put framelayour in my custom xml file or the xml of the activity – Senlers Kri Apr 18 '18 at 15:36
  • in your dialog fragment put frame layout as root layout – Devil10 Apr 18 '18 at 15:43