Passing null for root studio gives me this warning:
Avoid passing null as the view root (need to resolve layout parameters on the inflated layout\'s r
I found a good article about LayoutInflater
. The author explains how all the versions of the inflate
method work and gives examples of ListView
and AlertDialog
http://www.doubleencore.com/2013/05/layout-inflation-as-intended/
Update #1.
This answer recently helped me, too. https://stackoverflow.com/a/5027921/1065835
Here ya go, for some reason using View.inflate instead of inflating from a layoutinflater makes the lint error disappear. Thought I'd post this here since this thread is at the top of the Google Search...
view = View.inflate(context,R.layout.custom_layout,null);
Here is a picture for reference:
return inflater.inflate(R.layout.some_layout, container, true);
// for the last parameter use true, false or simply don't declare
When you really don't have any parent
(for example creating view for AlertDialog
), you have no other way than passing null
. So do this to avoid warning:
final ViewGroup nullParent = null;
convertView = layoutInflater.inflate(R.layout.list_item, nullParent);
Instead of doing
convertView = infalInflater.inflate(R.layout.list_item, null);
do
convertView = infalInflater.inflate(R.layout.list_item, parent, false);
It will inflate it with the given parent, but won't attach it to the parent.
For AlertDialog
bellow code can be used
convertView = layoutInflater.inflate(R.layout.list_item, findViewById(android.R.id.content), false);