Android 6.0和以下版本的AlertDialog中的requestFeature()错误

时间:2018-10-14 18:14:26

标签: java android alertdialog

我的应用程序中有一个AlerDialog,主要问题是在像Nougat或更高版本的版本中它可以工作,但是在Marsmallow或lolipop中,AlertDialog给出了requestFeature() must be called before adding content错误,但是我没有放置任何requestWindowFeature我的代码:

public Dialog onCreateDialog(Bundle savedInstanceState) {

    return createRadioListDialog();

}

public android.app.AlertDialog createRadioListDialog() {
    android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
    final CharSequence[] items = new CharSequence[3];

    items[0] = "Voy a asistir";
    items[1] = "No voy a asistir";
    items[2] = "Aún no lo sé";

    builder.setTitle("Asistencia")
            .setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (which == 0) {
                        asistenciaD = String.valueOf(1);
                        guardarMeta();
                        dialog.dismiss();
                        Objects.requireNonNull(getActivity()).getSupportFragmentManager().beginTransaction().replace(R.id.container, new Main_Fragment_Asistencia(), "MainFragment")
                                .commit();


                    }if (which == 1) {
                        asistenciaD = String.valueOf(2);
                        guardarMeta();
                        dialog.dismiss();

                        Objects.requireNonNull(getActivity()).getSupportFragmentManager().beginTransaction().replace(R.id.container, new Main_Fragment_Asistencia(), "MainFragment")
                                .commit();


                    }if (which == 2) {
                        asistenciaD = String.valueOf(0);
                        guardarMeta();
                        dialog.dismiss();

                        Objects.requireNonNull(getActivity()).getSupportFragmentManager().beginTransaction().replace(R.id.container, new Main_Fragment_Asistencia(), "MainFragment")
                                .commit();

                    }

                }
            });

    return builder.create();
   }
}

非常感谢您的回答

0 个答案:

没有答案