Is it possible to auto insert characters into an EditText as the user inputs data?
I.e. if the user is entering a long number such as <
For those still facing trouble with backspace and multiple hyphens -
new TextWatcher()
{
boolean hyphenExists;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (s.length() >= 6 && s.charAt(5) == '-') {
hyphenExists = true;
} else {
hyphenExists = false;
}
Log.d("TAG", "beforeTextChanged " + s.toString());
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.d("TAG", "onTextChanged " + s.toString());
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() == 5) {
if (!hyphenExists)
s.append('-');
}
Log.d("TAG", "afterTextChanged " + s.toString());
}
}