Simon
Simon

Reputation: 49

AlertDialog Button to open a new AlertDialog

I have an issue I can't handle. I am totally noob in Java, Android Studio, etc.
I want to make an AlertDialog with a Button and when I click on that Button I want to open a new AlertDialog.
Here is my code but it's not working, could you help me, please?

@Override
        public void onClick (View v){
            AlertDialog third = new AlertDialog.Builder(Quote2.this).create();
            third.setTitle("TITLE");
            third.setMessage("MESSAGE");
            third.setButton("Przykład", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            AlertDialog help = new AlertDialog.Builder(Quote2.this).create();
                            help.setTitle("Title");
                            help.setMessage("Message");
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            };
                            help.show();
                        }
                    });
            third.show();
            }
        });

Upvotes: 2

Views: 744

Answers (1)

Alexy Vercruysse
Alexy Vercruysse

Reputation: 269

I think you need to use setPositiveButton :

                AlertDialog.Builder third = new 
                AlertDialog.Builder(MainActivity.this);
                third.setTitle("TITLE");
                third.setMessage("MESSAGE");
                third.setPositiveButton("Przykład", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    AlertDialog.Builder help = new AlertDialog.Builder(MainActivity.this);
                    help.setTitle("Title");
                    help.setMessage("Message");
                    help.setPositiveButton("Stop", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    });
                    help.show();
                }
            });
            third.show();

Upvotes: 1

Related Questions