I need to replace the text inside the EditText while typing : Example : if the user pressed \"A\" it would be stored into a buffer and on the EditText \"D\" is displayed instead
In order to change the text interactively, you need to register a TextWatcher
. But trying to change the text inside the watcher creates further calls to the watcher. My hack is to temporarily remove the watcher when I want to change the text, and re-register it right after
mEditText.addTextChangedListener(new TextWatcher() {
@Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { }
@Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { }
@Override public void afterTextChanged(Editable editable) {
mEditText.removeTextChangedListener(this);
mEditText.setText(//TODO change whatever you like here);
mEditText.setSelection(editable.length()); //moves the pointer to end
mEditText.addTextChangedListener(this);
}