title: How can I get the results from an AlertDialog?
body: <p>I am using an AlertDialog.Builder to display a dialog to prompt the user to enter a password, I then want to save that password in a preference, however I can't figure out how to get the result from the alert dialog's input method.</p>
  
  <p>Here is essentially what I would like to be able to do:</p>
  
  <pre><code>    String result;
      AlertDialog.Builder b = new AlertDialog.Builder(this);
      b.setTitle("Please enter a password");
      final EditText input = new EditText(this);
      b.setView(input);
      b.setPositiveButton("OK", new DialogInterface.OnClickListener()
      {
          @Override
          public void onClick(DialogInterface dialog, int whichButton)
          {
             //I get a compile error here, it wants result to be final.
             result = input.getText().toString();
          }
      });
      b.setNegativeButton("CANCEL", null);
      b.create().show();
  </code></pre>
  
  <p>However, I am open to doing something such as <code>showDialog(int);</code> then using the <code>onCreateDialog(int)</code> method and somehow setting the result and receiving it in some other method, but I have no idea how to go about the last part.</p>