0

How to add a third button in alert dialog? I'm using an alert dialog in my code but I want to show multiple button in the dialog.

alertDialogBuilder
   .setMessage("Click yes to search on google")
   .setPositiveButton("Yes", new DialogInterface.OnClickListener()
   {
      public void onClick(
          DialogInterface dialog,
          int id) {
          // if this button is clicked, close current activity
          searchFor = contents;
          Intent viewSearch = new Intent(Intent.ACTION_WEB_SEARCH);
          viewSearch.putExtra(SearchManager.QUERY, searchFor);
          startActivity(viewSearch);
      }
   })
   .setNegativeButton("No", new DialogInterface.OnClickListener()
   {
     public void onClick(
          DialogInterface dialog,
          int id)
       {
         finish();
       }
   });
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
2
  • 1
    There is also a neutra button, you can set it in the same as you set negative and positive buttons Commented May 27, 2013 at 16:30
  • 1
    yup..setNeutralButton() is what you want.. Commented May 27, 2013 at 16:32

2 Answers 2

3

First of all there is setNeutralButton() method. This is the simplies one. The secodn one can be inflating extra XML view and then you can add as many buttons as you want.

Also I've found this answer, which seems quite interesting.

Sign up to request clarification or add additional context in comments.

Comments

0

You can have only 3 buttons max if you use the default style

use a custom View and do AlertDialog.Builder.setView(mycustomview);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.