Created
August 7, 2019 17:42
-
-
Save parzibyte/e3cb8cdc66203c1da0908b302399bdc6 to your computer and use it in GitHub Desktop.
Evento de Cambio de texto en EditText con Android y Java - https://parzibyte.me/blog/2018/10/19/evento-tecla-presionada-cambio-de-texto-edittext-android/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
editTextBusqueda.addTextChangedListener(new TextWatcher() { | |
// Antes de que el texto cambie (no debemos modificar nada aquí) | |
@Override | |
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
} | |
//Cuando esté cambiando...(no debemos modificar el texto aquí) | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, int count) { | |
} | |
/* | |
* Aquí el texto ya ha cambiado completamente, tenemos el texto actualizado en pocas palabras | |
* | |
* Por cierto, aquí sí podemos modificar el texto pero debemos tener cuidado para no caer en | |
* un ciclo infinito | |
* */ | |
@Override | |
public void afterTextChanged(Editable s) { | |
String elNuevoTexto = s.toString(); | |
// Hacer lo que sea con elNuevoTexto | |
Toast.makeText(getApplicationContext(), "Cambió a " + elNuevoTexto, Toast.LENGTH_SHORT).show(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment