title: How do you disable a button inside of an AlertDialog?
body: <p>I am trying to write an <code>AlertDialog</code> with 3 buttons. I want the middle, Neutral Button to be disabled if a certain condition is not met.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>int playerint = settings.getPlayerInt();
  int monsterint = settings.getMonsterInt();
  
  
  
          AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
          alertbox.setMessage("You have Encountered a Monster");
  
          alertbox.setPositiveButton("Fight!",
                  new DialogInterface.OnClickListener() {
  
                      // do something when the button is clicked
                      public void onClick(DialogInterface arg0, int arg1) {
                          createMonster();
                          fight();
  
                      }
                  });
  
          alertbox.setNeutralButton("Try to Outwit",
                  new DialogInterface.OnClickListener() {
  
                      // do something when the button is clicked
                      public void onClick(DialogInterface arg0, int arg1) {
                          // This should not be static
  //                      createTrivia();
                          trivia();
  
                      }
                  });
  
          // Return to Last Saved CheckPoint
          alertbox.setNegativeButton("Run Away!",
                  new DialogInterface.OnClickListener() {
  
                      // do something when the button is clicked
                      public void onClick(DialogInterface arg0, int arg1) {
                          runAway();
                      }
                  });
  
          // show the alert box
          alertbox.show();
  
  // Intellect Check
  
  Button button = ((AlertDialog) alertbox).getButton(AlertDialog.BUTTON_NEUTRAL);
  
          if(monsterint &gt; playerint) {
  
  
              button.setEnabled(false);
  
          }
      }
  </code></pre>
  
  <p>The line:   </p>
  
  <pre><code>Button button = ((AlertDialog) alertbox).getButton(AlertDialog.BUTTON_NEUTRAL);
  </code></pre>
  
  <p>Gives error: </p>
  
  <blockquote>
    <p>Cannot cast from AlertDialog.Builder to AlertDialog</p>
  </blockquote>
  
  <p>How do I fix this?</p>