I have an EditText with a TextWatcher. It is supposed to format the text to the height of the person, for example, 5'9 ". But when the user makes a mistake and wants to delete the foggy character, TextWather does not allow him to do this. Let them say that the user wants to delete" characther the TextWather immediately returns it back. Below is the code. So, how do I allow a user to delete text in an EditText?
private class CustomTextWatcher implements TextWatcher { private EditText mEditText; public CustomTextWatcher(EditText e) { mEditText = e; } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } public void afterTextChanged(Editable s) { int count = s.length(); String str = s.toString(); if (count == 1) { str = str + "'"; } else if (count == 3) { str = str + "\""; } else if ((count > 4) && (str.charAt(str.length() - 1) != '\"')) { str = str.substring(0, str.length() - 2) + str.charAt(str.length() - 1) + "\""; } else { return; } mEditText.setText(str); mEditText.setSelection(mEditText.getText().length()); }
}
source share