title: Android: AlertDialog with EditText does not automatically show the Keyboard
body: <p>I have an AlertDialog that is shown two times in a row. On a Nexus S everything works as I expect it, but on a Wildfire the Keyboard disappears, when the Dialog is shown for the second time.</p>
  
  <p>It must be some timing problem, because the keyboard is shown, when I put a breakpoint in the constructor and continue from there. Maybe onFocusChange is not the right place to make sure the keyboard should be shown.</p>
  
  <p>How can I fix it? What would you look for in order to find the reason behind this problem?</p>
  
  <pre><code>/**
   * Show a dialog asking the user to confirm the PIN.
   */
  private static abstract class PinConfirmationDialog extends AlertDialog {
  
      protected PinConfirmationDialog(Context context, final int titleResource) {
          super(context);
          setTitle(titleResource);
  
          // Set an EditText view to get user input 
          final EditText input = new EditText(context);
          InputFilter[] FilterArray = new InputFilter[1];
          FilterArray[0] = new InputFilter.LengthFilter(4);
          input.setFilters(FilterArray);
          input.setKeyListener(DigitsKeyListener.getInstance(false,true));
          input.setInputType(InputType.TYPE_CLASS_NUMBER
                  | 16 /*InputType.TYPE_NUMBER_VARIATION_PASSWORD Since: API Level 11*/);
          input.setTransformationMethod(new PasswordTransformationMethod());
          setView(input);
  
          setButton(context.getString(R.string.okay_action), new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  onOkButtonClicked(input.getText().toString());
              }
          });
          setButton2(context.getString(R.string.cancel_action), new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  onCancelButtonClicked();
              }
          });
  
          input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
              @Override
              public void onFocusChange(View v, boolean hasFocus) {
                  if (hasFocus) {
                    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                  }
              }
          });
      }
  
      /**
       * OK Button was pressed
       * @param pinCode The code the user has entered
       */
      abstract void onOkButtonClicked(String pinCode);
  
      /**
       * Override method if needed
       */
      protected void onCancelButtonClicked() {
      }
  }
  </code></pre>