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

前端 未结 10 724
面向向阳花
面向向阳花 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:22

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

提交回复
热议问题