title: Android - Capture "Done" and "Enter" key events on soft keyboard
body: <p>I have a <strong>Login</strong> page in my app where there are elements as listed: </p>
  
  <ul>
  <li>username (EditText)</li>
  <li>password (EditText)</li>
  <li>Login    (Button)</li>
  </ul>
  
  <p>On pressing <code>Login</code>, it will land into the main screen. The intention is to perform that same action when the user hits <code>Done</code> at the completion of keying in the password on soft keyboard on <code>Samsung Galaxy S3</code>; and <code>Enter</code> key of soft keyboard on <code>HTC One X</code>.</p>
  
  <p>So,  here is how the EditText of Password field is:</p>
  
  <pre><code>&lt;EditText
      android:id="@+id/password_txt"
      android:layout_width="200dip"
      android:layout_height="wrap_content"
      android:imeOptions="flagNoExtractUi"
      android:inputType="textPassword"
      android:paddingLeft="10dp"
      android:paddingRight="10dp"
      android:paddingTop="8dp"
      android:singleLine="true" /&gt;
  </code></pre>
  
  <p>In the Activity, whatever I tried is here:</p>
  
  <pre><code>EditText mPassword = (EditText) findViewById(R.id.password_txt);
  mPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  
                  @Override
                  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                      if(event.getAction() == KeyEvent.ACTION_DOWN &amp;&amp; event.getKeyCode() == KeyEvent.KEYCODE_ENTER || actionId == EditorInfo.IME_ACTION_DONE){
                          Log.e("MyApp", " ------&gt; IN EDITOR ACTION DONE");
                      }
                      return false;
                  }
              });
  </code></pre>
  
  <p>I did try with keeping the imeOptions for the Password field as <code>actionDone</code> along with the <code>flagNoExtractUi</code> but it didn't work out.</p>