Use this code to inflate the dialog view without a warning:
View.inflate(context, R.layout.dialog_edit, null);
The short story is that when you are inflating a view for a dialog, parent
should be null, since it is not known at View inflation time. In this case, you have three basic solutions to avoid the warning:
inflate(int resource, ViewGroup root, boolean attachToRoot)
. Set attachToRoot
to false
.This tells the inflater that the parent is not available.Check out http://www.doubleencore.com/2013/05/layout-inflation-as-intended/ for a great discussion of this issue, specifically the "Every Rule Has an Exception" section at the end.
You should use AlertDialog.Builder.setView(your_layout_id)
, so you don't need to inflate it.
Use AlertDialog.findViewById(your_view_id)
after creating the dialog.
Use (AlertDialog) dialogInterface
to get the dialog
inside the OnClickListener
and then dialog.findViewById(your_view_id)
.
Casting null as ViewGroup resolved the warning:
View dialogView = li.inflate(R.layout.input_layout,(ViewGroup)null);
where li
is the LayoutInflater's
object.
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