在片段中未找到警报对话框的视图

问题描述 投票:0回答:1

我正在尝试填充活动的警报对话框(带有具有EditText和Button的布局文件)在片段内。通过在对应的classfragment'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);

谁能找到实际的问题是什么?谢谢!

android android-layout android-fragments android-alertdialog
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.