Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element) Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element) android android

Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element)


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.


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);