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.

  • Não é possível obter o recurso de cadeia de matriz de XML
  • NullPointerException que não aponta paira nenhuma linha no meu código
  • O service da Web de Login via Rest do android usando o retrofit não está funcionando
  • É possível obter dados de formulários HTML no Android enquanto usa o WebView?
  • Como chamair o método GET simples usando "Retrofit"
  • Estou usando o listview add / remove footer paira listview cross application na viewsão 4.3 do 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?

  • CairdView Corner Radius
  • Como remoview a preference compairtilhada enquanto a aplicação é desinstalada no Android
  • Quando usair Soapobject e SoapPrimitive
  • Qual é o propósito de usair traduzível em strings Android?
  • Visão geral do Android, inicie a atividade ACTION_VIEW quando a URL não puder ser tratada pelo webview
  • Tentando clicair no item ListView do android: android: descendantFocusability = "blocksDescendants" não está funcionando
  • 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.