title: Don't close AlertDialog after button is clicked
body: <p>I need help!</p>
  
  <p>I'm developing an android app and I ran into a problem.
  I have an <code>AlertDialog</code> which contains two buttons(positive and negative). When a button is clicked certain code runs, then the dialog is closed.</p>
  
  <pre><code>dialog.setNegativeButton("button name", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              // some code
          }
      });
  </code></pre>
  
  <p>But that's not what I want. When the users clicks the negative button I want some code to run and then the dialog SHOULDN'T be closed.</p>
  
  <pre><code>dialog.setNegativeButton("button name", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              // some code
              // code to prevent the dialog from being closed ?
          }
      });
  </code></pre>
  
  <p>Is there anything I can do to prevent the dialog from being closed when the positive or negative button is clicked ?</p>
  
  <p>I tried using this code: </p>
  
  <pre><code>dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setEnabled(false);
  </code></pre>
  
  <p>But it doesn't work because now the user can't click the button.</p>
  
  <p>BTW I'm developing for minimum sdk version of 16.</p>
  
  <p>Thanks for helping!</p>