Using beforeTextChanged will not be useful, because it will not interrupt the actual key print in EditText. I would use something similar to:
public void afterTextChanged(Editable s) { if(s.length() > 0 && s.toString().charAt(s.length()-1) == 'S') { final String newText = s.toString().substring(0, s.length()-1) + "a"; editText.setText(newText); } }
I added some toString (), not 100% sure that Editable works, but I think it should cover it.
source share