2
I’m trying to put a phone mask on by the method onTextChanged
, the text received in this method is coming in reverse, and when I try to put the method setSelection
() for the cursor to position at the end, my EditText
is deleted in Galaxy Tab 10. How to solve this?
private TextWatcher filterTextWatcherTelefone = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
try {
if (atualizando) {
atualizando = false;
return;
}
String resultado = limparFormatacaoNumero(s.toString());
if (isNumero(resultado)) {
if (resultado.length() <= 14) {
resultado = adicionarFormatacaoTelefone(resultado);
} else {
resultado = resultado.substring(0, 14);
resultado = adicionarFormatacaoTelefone(resultado);
}
atualizando = true;
textoDiscagem.setText(resultado);
textoDiscagem.setSelection(textoDiscagem.getText().length());
}
} catch (Exception e) {
}
}
};
Have you even tested the
PhoneNumberFormattingTextWatcher
? Check the documentation to see how to configure it: http://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher.html.– Wakim