teclado tapa studio salto que personalizar ocultar obtener mascara linea event edittext datos android android-softkeyboard

tapa - salto de linea edittext android



Android ocultó el teclado al presionar enter(en un EditText) (5)

Cuando mi usuario presiona Enter en el androide virtual "user validate entry!" teclado mi teclado permanece visible! (¿Por qué?)

Aquí mi código de Java ...

private void initTextField() { entryUser = (EditText) findViewById(R.id.studentEntrySalary); entryUser.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: userValidateEntry(); return true; } } return true; } }); } private void userValidateEntry() { System.out.println("user validate entry!"); }

... aquí mi vista

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <EditText android:id="@+id/studentEntrySalary" android:text="Foo" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>

Tal vez algo mal en mi dispositivo virtual?


Esto debería hacerlo:

yourEditTextHere.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // NOTE: In the author''s example, he uses an identifier // called searchBar. If setting this code on your EditText // then use v.getWindowToken() as a reference to your // EditText is passed into this callback as a TextView in.hideSoftInputFromWindow(searchBar .getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); userValidateEntry(); // Must return true here to consume event return true; } return false; } });


Estoy creando un componente personalizado que extiende AutoCompleteTextView, como en el siguiente ejemplo:

public class PortugueseCompleteTextView extends AutoCompleteTextView { ... @Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_BACK)) { InputMethodManager inputManager = (InputMethodManager) getContext(). getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow( this.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return super.onKeyPreIme(keyCode, event); }

Estoy usando este código en AlertDialog.Builder, pero es posible usarlo para Activity.


Mantenga el singleLine = "true" y agregue imeOptions = "actionDone" al EditText. Luego, en OnEditorActionListener, compruebe si actionId == EditorInfo.IME_ACTION_DONE, así (pero cámbielo a su implementación):

if (actionId == EditorInfo.IME_ACTION_DONE) { if ((username.getText().toString().length() > 0) && (password.getText().toString().length() > 0)) { // Perform action on key press InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(username.getWindowToken(), 0); doLogin(); } }



sólo agrega esta línea en tu texto de edición.

android:imeOptions="actionDone"''

puede especificar la siguiente ID de edición de texto para moverse a ese texto de edición al hacer clic en el botón de teclado realizado.