Dialog.getWindow () devuelve null después de crear el cuadro de diálogo
@Override protected Dialog onCreateDialog(int id) { Dialog dialog = null; switch(id) { case DIALOG_ID: LayoutInflater inflater = getLayoutInflater(); View InfoLayout = inflater.inflate(R.layout.info_dialog, null); AlertDialog.Builder b = new AlertDialog.Builder(MyActivity.this) .setView(InfoLayout ); initInfoDialog(dialog); return dialog; ... private void initInfoDialog(Dialog dialog) { //this line has the null pointer WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
¿Por qué dialog.getWindow () devuelve null en este caso?
Me enfrenté al mismo problema y ahora veo que la documentación de getWindow () está diciendo realmente por qué (no la razón pero por qué en este punto específico). Puede recuperar la ventana después de llamar a show () .