TextWatcherused for notification every time types are used.
InputFilterdecides what can be entered.
For example,
suppose I want the user to enter a temperature. This temperature should be all numbers and can contain only two digits after the decimal. If you look closely, I need both TextWatcher, and InputFilter.
InputFilter allows only numbers.
final InputFilter[] filters = new InputFilter[]
{ DigitsKeyListener.getInstance(true, true) };
textView.setFilters(filters);
This will now allow numbers with more than two digits after the decimal number. What for? Because it InputFilterlimits only what keys can be entered. Here when TextWatcherit comes in.
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!textView.hasWindowFocus() || textView.hasFocus() || s == null){
return;
}
}
source
share