title: Keyboard doesn't accept first character when changing inputs
body: <p>I have a TextWatcher set on an EditText that changes the input type after a user types a number followed by a space. </p>
  
  <p>If the user types two numbers the input type switches and accepts the next character, but if the user types only one number and presses space the input type still changes but it won't accept the first character the user tries to input.</p>
  
  <p>I've tested this on Froyo and 1.6, it only happens on Froyo, 1.6 works like it should.</p>
  
  <p>Here's the code: </p>
  
  <pre><code>    TextWatcher watcher = new TextWatcher() {
      @Override
      public void afterTextChanged (Editable s) {
      }
  
      @Override
      public void beforeTextChanged (CharSequence s, int start, int count, int after) {
      }
  
      @Override
      public void onTextChanged (CharSequence s, int start, int before, int count) {          
          // Parsed text holder is a class that just parses the EditText and pulls out various parts.
          ParsedTextHolder th = parseTextHolder(s);
  
          String newText = "";
          Boolean setTextKeyListener = false;
  
          String tGetTextString = mQuery.getText().toString();
  
          if (!th.pFullMatch.equals("")) {
              if (th.pFullMatch.length() == 2) {
                  mQuery.setKeyListener(new
                  TextKeyListener(TextKeyListener.Capitalize.SENTENCES, true));
                  newText = tGetTextString + " for ";
                  setTextKeyListener = true;
              }
          }
  
          if (setTextKeyListener) {
              Log.i("setTextKeyListener", "true");
              if (mQuery.getKeyListener().getClass() != TextKeyListener.class) {
                      mQuery.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.SENTENCES, true));
              } else {
                      Log.d("setTextKeyListener", "skipped. already was text.");
              }
  
              if (!newText.equals("")) {
                      int position = newText.length();
                      String ttext = newText;
                      newText = "";
                      mQuery.setText(ttext, TextView.BufferType.EDITABLE);
                      mQuery.setText(ttext);
                      Editable text = mQuery.getEditableText();
                      Log.w("setting selectiont to text: ", text.toString());
                      Log.w("setting selectiont to position: ", Integer.toString(position));
                      Selection.setSelection(text, position);
                      mQuery.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.SENTENCES, true));
              }
  
          }
      }
  };
  </code></pre>
  
  <p>Also, here's an APK if you want to see what the bug is like: <a href="http://endlesswhileloop.com/files/KeyboardBug.apk" rel="nofollow noreferrer">http://endlesswhileloop.com/files/KeyboardBug.apk</a></p>