Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid passing null as the view root (when inflating custom layout in AlertDialog)

Trying to inflate a custom layout for an AlertDialog, but keep getting this waring. I've seen several different solutions to this but don't know which is correct for my scenario. What is the actual correct way of getting rid of this null warning?

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

@Override
public void onClick(View v) {
  AlertDialog alertDialog = new 
  AlertDialog.Builder(getActivity()).create();

  LayoutInflater inflater = getActivity().getLayoutInflater();
  View content = inflater.inflate(R.layout.dialog_customd, null);
  alertDialog.setView(content);

  alertDialog.show();
}
like image 540
wbk727 Avatar asked Jul 31 '17 15:07

wbk727


1 Answers

You may try to use:

View.inflate(context, R.layout.dialog_customd, null);
like image 92
Dmitry Ushkevich Avatar answered Sep 20 '22 16:09

Dmitry Ushkevich