0

I used this code to generate alert dialog in android. But i want yes button in the left and no button in the right. How can i do this??

AlertDialog.Builder    builder = new    AlertDialog.Builder(
                        getApplicationContext());
                builder.setCancelable(true);
                builder.setTitle("Title");
                builder.setInverseBackgroundForced(true);
                builder.setPositiveButton("Yes",
                        new     DialogInterface.OnClickListener() {
                            @Override
                            public   void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.dismiss();
                            }
                        });
                builder.setNegativeButton("No",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.dismiss();
                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();
Sanny Pathak
  • 45
  • 1
  • 9
  • replace text and also add event as per your requirement, – Dhaval Parmar Jun 05 '15 at 04:22
  • whether it is set negative or positive... you can add your event as you wish. so as Dhaval said you can fire appropriate event on whichever button you want. –  Jun 05 '15 at 04:26

1 Answers1

2

you can change the text in positive nagative buttons as your wish and and write what ever code in that.

AlertDialog.Builder    builder = new    AlertDialog.Builder(
                            getApplicationContext());
                    builder.setCancelable(true);
                    builder.setTitle("Title");
                    builder.setInverseBackgroundForced(true);
                    builder.setPositiveButton("No",
                            new     DialogInterface.OnClickListener() {
                                @Override
                                public   void onClick(DialogInterface dialog,
                                        int which) {
                                    dialog.dismiss();
                                }
                            });
                    builder.setNegativeButton("Yes",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    dialog.dismiss();
                                }
                            });
                    AlertDialog alert = builder.create();
                    alert.show();
ravi
  • 319
  • 3
  • 15