我正在尝试填充活动的警报对话框(带有具有EditText和Button的布局文件)在片段内。通过在对应的class的fragment's中调用findViewById()找不到组件。我已经在类中编写了此代码:
AlertDialog.Builder builder=new AlertDialog.Builder(context);
View v=getLayoutInflater().inflate(R.layout.layout_alert_dialog,null);
final EditText txtAddNew=v.findViewById(R.id.txtAddNew); //null
final TextView txtErr = v.findViewById(R.id.txtErr); //null
Button btnAdd=v.findViewById(R.id.btnAdd); //null
我认为问题出在这行代码:
View v=getLayoutInflater().inflate(R.layout.layout_alert_dialog,null);
谁能找到实际的问题是什么?谢谢!