Use an InputFilter like this
InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if (Character.isLetter(source.charAt(i)) {
if (Character.isLetter(source.charAt(i - 1)) {
return "";
}
}
}
};
}
You can also use the TextWatcher class to get the same functionality
Ref:How to use the TextWatcher class in Android?
myEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String str = s.toString();
if (str.substring(str.length-3,s.length-1)).equals("xx") {
//put in code to remove the last x via code
}
}
@Override
public void afterTextChanged(Editable s) {
// Do nothing
}
});