“Avoid passing null as the view root” warning when inflating view for use by AlertDialog

前端 未结 10 729
面向向阳花
面向向阳花 2020-12-12 15:41

I get the lint warning, Avoid passing null as the view root when inflating views with null as parent, like:

LayoutInfl         


        
10条回答
  •  伪装坚强ぢ
    2020-12-12 16:39

    Instead of doing

    view = inflater.inflate(R.layout.list_item, null);
    

    do

    view = inflater.inflate(R.layout.list_item, parent, false);
    

    It will inflate it with the given parent, but won't attach it to the parent.

    Many thanks to Coeffect (link to his post)

提交回复
热议问题