yourEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// you can call or do what you want with your EditText here
yourEditText. ...
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
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.isLetterOrDigit(source.charAt(i))) {
return "";
}
}
return null;
}
};
edit.setFilters(new InputFilter[]{filter});
yourEditText.addTextChangedListener(new TextWatcher() {
CharSequence previous;
public void afterTextChanged(Editable s) {
if(s.toString().contains("&^%$#*&(")){
s.clear();
s.append(previous.toString());
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
previous = s;
}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
private InputFilter filter = new InputFilter() {
// An example pattern that restricts the input only to the lowercase letters
private static final Pattern restrictedChars = Pattern.compile("[a-z]*")
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
final CharSequence replacementText = source.subSequence(start, end);
final CharSequence replacedText = dest.subSequence(dstart, dend);
if (source == null || restrictedChars.matcher(replacementText).matches()) {
return null; // Accept the original replacement
}
return replacedText; // Keep the original text
}
};