gpt4 book ai didi

android - 避免将 null 作为 View 根传递(在 AlertDialog 中扩展自定义布局时)

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:16 25 4
gpt4 key购买 nike

尝试为 AlertDialog 扩展自定义布局,但不断收到此警告。我已经看到了几种不同的解决方案,但不知道哪个适合我的场景。摆脱此空警告的实际正确方法是什么?

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

最佳答案

您可以尝试使用:

View.inflate(context, R.layout.dialog_customd, null);

关于android - 避免将 null 作为 View 根传递(在 AlertDialog 中扩展自定义布局时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45419680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com