title: Android: EditText in Dialog doesn't pull up soft keyboard
body: <p>So I've got what seems to be a common problem, which is that the EditText in my dialog box doesn't show up when it gets focus. I've seen several workarounds, such as in <a href="https://stackoverflow.com/questions/4023975/android-dialog-box-show-soft-keyboard-automatically-when-focus-is-on-an-edittex">this thread</a>, <a href="https://stackoverflow.com/questions/2403632/android-show-soft-keyboard-automatically-when-focus-is-on-an-edittext/2403977#2403977">this one</a> and <a href="https://stackoverflow.com/questions/7294198/no-soft-keyboard-for-the-edittext-inside-the-dialog-box">this one</a> (and many more), but I have never seen a satisfactory explanation for <em>why</em> this is happening in the first place. </p>
  
  <p>I would much prefer to have android use its own default behavior for EditTexts than to build my own, but it seems like everyone (in those threads) has accepted that the default behavior for EditTexts in Dialogs is to just give a cursor and no keyboard. Why would that be?</p>
  
  <p>For the record, none of these workarounds seem to be working for me - the closest I've been able to come is forcing a keyboard to appear <em>underneath</em> the dialog box (using InputMethodManager.toggleSoftKeyboard(*)). My particular configuration is API15, the EditText shows up in a footer on a ListView within an AlertDialog. The EditText android:focusable="true" is set, and onFocusChangeListener <em>is</em> receiving focus events.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>As requested, here is the specific code snippet that I'm working with. I won't bother with the whole layout, but in this specific application, the EditText appears in response to pressing a button on the dialog (similar to <a href="http://developer.android.com/guide/topics/ui/actionbar.html#ActionView" rel="noreferrer">an action view</a>). It is contained in a RelativeLayout which by default has visibility "gone":</p>
  
  <pre><code> &lt;RelativeLayout 
         android:id="@+id/relLay"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_centerVertical="true"
         android:visibility="gone"
         android:layout_marginTop="5dp"
         android:layout_marginBottom="5dp"&gt;
  
          &lt;ImageButton
              android:id="@+id/cancelBut"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:background="@color/transparent"
              android:src="@drawable/cancelButton" 
              android:layout_margin="5dp"/&gt;
  
          &lt;ImageButton
              android:id="@+id/okBut"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_toLeftOf="@id/cancelBut"
              android:background="@color/transparent"
              android:src="@drawable/okButton"
              android:layout_margin="5dp" /&gt;
  
          &lt;EditText 
              android:id="@+id/editText"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:inputType="text"
              android:focusable="true"
              android:layout_toLeftOf="@id/okBut"/&gt;
     &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>The code which builds this sets the visibility of the relativeLayout to "Visible" (and hides the other UI elements). This <em>should</em> be enough to pull up the keyboard when the EditText gets focused, based on my experience with EditText. However, for some reason this is not the case.  I can set the following onFocusChangeListener:</p>
  
  <pre><code>    edit_text.setOnFocusChangeListener(new OnFocusChangeListener() {
  
              @Override
              public void onFocusChange(View v, boolean hasFocus) {
                  // For whatever reason we need to request a soft keyboard.
                      InputMethodManager imm = (InputMethodManager)dlg.getWindow().getContext().getSystemService(_Context.INPUT_METHOD_SERVICE);
                      if(hasFocus)
                          imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                      Log.v("DialogProblem", "Focus requested, " + (hasFocus?"has focus.":"doesn't have focus."));
                  }
              }
          });
  </code></pre>
  
  <p>Using this configuration, when I <em>first</em> enter the EditText, the onFocusChangedListener triggers, and generates a log that invariably looks like this:</p>
  
  <pre><code>Focus requested, has focus.
  Focus requested, doesn't have focus.
  Focus requested, has focus.
  </code></pre>
  
  <p>The keyboard shows up and then disappears, probably because I toggle it twice, but even when I make sure it stays up, it's <em>behind</em> the dialog window (in a greyed out area), and there's no way to get to it without closing the dialog.</p>
  
  <p>That said, I'd like to emphasize that even though I may be able to get this work-around to work, I'm <em>primarily interested</em> in finding a simple reason <em>why</em> the EditText isn't triggering in the first place, and why this seems to be so commonplace!</p>