Problem inflating custom view for AlertDialog in DialogFragment

The first error line gives me the hint that this is related to how you are creating your dialog – not the dialog itself.

Are you creating the dialog automatically (which could mean this gets called before the views are all set up) or in response to a button click? I initially had problems with fragments due to instantiation order.

I used the same code to set the view as you have, and my result works. I cut out the other setup to make this look cleaner, but it works with or without it.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_layout, null);
    builder.setView(view);

    return builder.create();
}

Leave a Comment