Controle a tecla Enter no EditText em diferentes dispositivos

Agora estou processando a key enter em meus campos EditText usando um onEditorActionListener e olhando a ID da ação paira IME_NULL. Funciona bem paira todos os meus users, exceto um. Ela tem um Xperia Arc.

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; } }; 

Depois de aprender sobre o problema, tentei outra abordagem usando um onKeyListener e procurando o evento-key ACTION_DOWN e, em seguida, viewificando o código da key se coincidisse com KEYCODE_ENTER.

  • Inclua files .java como files de origem java no Android Studio paira remoview o círculo viewmelho com "J" neles
  • Verificação do número de telefone do Android
  • Escape de múltiplos cairacteres "%" no Android
  • Android N Preview emulator crash
  • Singleton no Android
  • Conecte-se à VPN no Genymotion Android
  •  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; } }); { 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; } }); } 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; } }); retornair viewdadeiro; 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; } }); } 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; } }); } 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; } }); retornair falso; 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; } }); } 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; } }); 

    Sem dados sobre isso também. Estou com uma perda agora. Há muitos aplicativos que manipulam a key enter bem. O que eles estão fazendo de maneira diferente?

  • Alterando a senha da key de assinatura do Android
  • setOnTabSelectedListener é obsoleto é solicitado ao criair o layout da guia
  • Faça o Android TextView invisível até que o button seja pressionado?
  • Como declairo uma bairra de ferramentas / Bairra de ação de altura estendida no Android Lollipop?
  • Como rebuild o aplicativo "Launcher" padrão?
  • Precisa usair o cliente Team Foundation no Android Studio alternativas prováveis ​​/ soluções alternativas?
  • 3 Solutions collect form web for “Controle a tecla Enter no EditText em diferentes dispositivos”

    Eu descobri como conseguir que ele funcionasse.

    Eu tive que adicionair android: singleLine = "true" paira a tag EditText no layout XML (alternadamente, você pode configurá-lo usando setSingleLine () no código). Isso força o text de edição a usair apenas uma linha e o foco irá paira a próxima checkbox EditText.

    Experimente esta solução: (Eu não testei isso)

    Defina a seguinte propriedade paira o seu EditText

     android:imeOptions="actionNext" 

    Agora, você pode configurair o seguinte onEditorAction

     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_NEXT) { // Program Logic Here return true; } return false; } retornair viewdadeiro; public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_NEXT) { // Program Logic Here return true; } return false; } } public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_NEXT) { // Program Logic Here return true; } return false; } retornair falso; public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_NEXT) { // Program Logic Here return true; } return false; } 

    Paira algumas funcionalidades adicionais, você pode configurair sua senha EditText paira:

     android:imeOptions="actionDone" 

    Então, você pode ter algo assim:

     TextView.OnEditorActionListener keyListener = new TextView.OnEditorActionListener(){ public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if(actionId == EditorInfo.IME_ACTION_NEXT) { ((EditText) findViewById(R.id.etPass)).requestFocus(); } if (actionId == EditorInfo.IME_ACTION_DONE) { logon(); } return true; } }; } TextView.OnEditorActionListener keyListener = new TextView.OnEditorActionListener(){ public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if(actionId == EditorInfo.IME_ACTION_NEXT) { ((EditText) findViewById(R.id.etPass)).requestFocus(); } if (actionId == EditorInfo.IME_ACTION_DONE) { logon(); } return true; } }; } TextView.OnEditorActionListener keyListener = new TextView.OnEditorActionListener(){ public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if(actionId == EditorInfo.IME_ACTION_NEXT) { ((EditText) findViewById(R.id.etPass)).requestFocus(); } if (actionId == EditorInfo.IME_ACTION_DONE) { logon(); } return true; } }; retornair viewdadeiro; TextView.OnEditorActionListener keyListener = new TextView.OnEditorActionListener(){ public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if(actionId == EditorInfo.IME_ACTION_NEXT) { ((EditText) findViewById(R.id.etPass)).requestFocus(); } if (actionId == EditorInfo.IME_ACTION_DONE) { logon(); } return true; } }; } TextView.OnEditorActionListener keyListener = new TextView.OnEditorActionListener(){ public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if(actionId == EditorInfo.IME_ACTION_NEXT) { ((EditText) findViewById(R.id.etPass)).requestFocus(); } if (actionId == EditorInfo.IME_ACTION_DONE) { logon(); } return true; } }; 
     (EditText) passwordView = (EditText) findViewById(R.id.password); passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordView.setOnEditorActionListener(new OnEditorActionListener() { @Oviewride public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String input; if(actionId == EditorInfo.IME_ACTION_DONE) { input= v.getText().toString(); Toast toast= Toast.makeText(LogIn.this,input, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } return false; } }); { (EditText) passwordView = (EditText) findViewById(R.id.password); passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordView.setOnEditorActionListener(new OnEditorActionListener() { @Oviewride public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String input; if(actionId == EditorInfo.IME_ACTION_DONE) { input= v.getText().toString(); Toast toast= Toast.makeText(LogIn.this,input, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } return false; } }); { (EditText) passwordView = (EditText) findViewById(R.id.password); passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordView.setOnEditorActionListener(new OnEditorActionListener() { @Oviewride public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String input; if(actionId == EditorInfo.IME_ACTION_DONE) { input= v.getText().toString(); Toast toast= Toast.makeText(LogIn.this,input, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } return false; } }); { (EditText) passwordView = (EditText) findViewById(R.id.password); passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordView.setOnEditorActionListener(new OnEditorActionListener() { @Oviewride public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String input; if(actionId == EditorInfo.IME_ACTION_DONE) { input= v.getText().toString(); Toast toast= Toast.makeText(LogIn.this,input, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } return false; } }); retornair viewdadeiro; (EditText) passwordView = (EditText) findViewById(R.id.password); passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordView.setOnEditorActionListener(new OnEditorActionListener() { @Oviewride public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String input; if(actionId == EditorInfo.IME_ACTION_DONE) { input= v.getText().toString(); Toast toast= Toast.makeText(LogIn.this,input, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } return false; } }); } (EditText) passwordView = (EditText) findViewById(R.id.password); passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordView.setOnEditorActionListener(new OnEditorActionListener() { @Oviewride public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String input; if(actionId == EditorInfo.IME_ACTION_DONE) { input= v.getText().toString(); Toast toast= Toast.makeText(LogIn.this,input, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } return false; } }); retornair falso; (EditText) passwordView = (EditText) findViewById(R.id.password); passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordView.setOnEditorActionListener(new OnEditorActionListener() { @Oviewride public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String input; if(actionId == EditorInfo.IME_ACTION_DONE) { input= v.getText().toString(); Toast toast= Toast.makeText(LogIn.this,input, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } return false; } }); } (EditText) passwordView = (EditText) findViewById(R.id.password); passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordView.setOnEditorActionListener(new OnEditorActionListener() { @Oviewride public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String input; if(actionId == EditorInfo.IME_ACTION_DONE) { input= v.getText().toString(); Toast toast= Toast.makeText(LogIn.this,input, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return true; } return false; } }); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.