如何访问自定义警报对话框的布局参数...?

时间:2011-10-11 15:52:23

标签: android android-layout android-widget android-alertdialog

我得到空指针异常,

由于无法识别自定义警告对话框中的布局参数。

所以,如果有人知道这个,请帮助我......?

提前致谢...!

builder = new AlertDialog.Builder(this);
        builder.setView(getLayoutInflater().inflate(R.layout.custom_dialog, null));
        //AlertDialog dialog = new AlertDialog.Builder(this).create();
        //dialog.setContentView(R.layout.custom_dialog);
        dialog = builder.create();
        customDialogList = (ListView) dialog.findViewById(R.id.custom_list);
        customDialogList.setAdapter(customDialogAdapter); // here null pointer exception    
        dialog.setCancelable(true);
        dialog.show();

1 个答案:

答案 0 :(得分:1)

builder = new AlertDialog.Builder(this);
        view customView = getLayoutInflater().inflate(R.layout.custom_dialog, null);
        builder.setView(customView);
        //AlertDialog dialog = new AlertDialog.Builder(this).create();
        //dialog.setContentView(R.layout.custom_dialog);
        dialog = builder.create();
        customDialogList = (ListView) customView.findViewById(R.id.custom_list);
        customDialogList.setAdapter(customDialogAdapter);   
        dialog.setCancelable(true);
        dialog.show();

试试这个。