Note that there are some explanatory texts on larger screens.

plurals
  1. POHandle enter key in EditText across different devices
    text
    copied!<p>Right now I'm handling the enter key in my EditText fields using a an onEditorActionListener and looking at the Action ID for IME_NULL. It works fine for all my users except one. She has an Xperia Arc.</p> <pre><code>TextView.OnEditorActionListener keyListener = new TextView.OnEditorActionListener(){ public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if(actionId == EditorInfo.IME_NULL){ if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.etUser))){ ((EditText) findViewById(R.id.etPass)).requestFocus(); } if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.etPass))){ logon(); } } return true; } }; </code></pre> <p>After learning about the issue, I tried another approach by using an onKeyListener and looking for the key event ACTION_DOWN then checking the keycode if it matched KEYCODE_ENTER.</p> <pre><code>EditText etUserName = (EditText) findViewById(R.id.etUser); etUserName.setOnKeyListener(new OnKeyListener() { public boolean onKey(View view, int keyCode, KeyEvent event){ if (event.getAction() == KeyEvent.ACTION_DOWN){ switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.etUser))){ ((EditText) findViewById(R.id.etPass)).requestFocus(); } return true; default: break; } } return false; } }); </code></pre> <p>No dice on that either. I'm at a loss right now. There are plenty of apps out there that handle the enter key just fine. what are they doing differently?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload