0

I've a problem with my DialogFragment

public class HorairesFragment extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        LayoutInflater i = getActivity().getLayoutInflater();
        mView = i.inflate(R.layout.intervention_horaires_fragment, null);
        AlertDialog.Builder b=  new  AlertDialog.Builder(getActivity())
                .setPositiveButton(R.string.ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {

                            AlertDialog alert = new AlertDialog.Builder(getFragmentManager())
                            .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog, int id) {
                                     dialog.cancel();
                                 }
                            }).create();
                            alert.setMessage(message);
                            alert.setCancelable(false);
                            alert.show();

                            }
                        }
                )
                .setNegativeButton(R.string.annuler,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                            }
                        }
                );
        b.setView(mView);
        return b.create();
    }
}

I removed the code for the readability. below is a screenshot of my DialogFragment

enter image description here

Sometimes the user enter some incorrect data, so when I click on the OK button, I need to show an AlertDialog with a custom error message (or a Toast maybe).

The problem follows : when he clicks on OK OK in the AlertDialog, it dismiss also my dialog

enter image description here

Is it possible to correct that behaviour ?

P. Sohm
  • 2,842
  • 2
  • 44
  • 77
  • How about showing the dialog again after the error dialog? – Niko Adrianus Yuwono Nov 01 '15 at 23:59
  • buttons on alert dialog always dismiss the alert dialog, it is not a matter of the second dialog. – njzk2 Nov 02 '15 at 00:12
  • +njzk2 you are right. if I remove the positive button on the first DialogFragment and convert it for example to a button. the problem is solved. I'm looking now for styling the two button like in material dialog .. – P. Sohm Nov 02 '15 at 08:56

1 Answers1

0

This post should help you solve your problem:

How to prevent a dialog from closing when a button is clicked

An alternative solution would be to implement your own Dialog class.

Community
  • 1
  • 1
Markus Maga
  • 377
  • 2
  • 7