Как получить доступ к параметрам макета для пользовательского диалогового окна оповещения …?

#android #android-layout #android-widget #android-alertdialog

#Android #android-layout #android-виджет #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. На что указывает ваш nullpointer в вашем коде?

2. Обновлен код @coder_For_Life22.

Ответ №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();
  

попробуйте это.