Reputation: 61
int maxLength = 20;
private String blockCharacterSet = "~#^|$%'&*!;";
private InputFilter filter = new InputFilter()
{
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
if (source != null && blockCharacterSet.contains(("" + source))) {
return "";
}
return null;
}
};
Here only one filter is working either blockCharacterSet or max length:
EditText etname;
etname.setFilters(new InputFilter[] { filter });
etname.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLength)});
Can anyone please help me to set above two filters at a time?
Upvotes: 6
Views: 3605
Reputation: 2700
If you have two inputFilters, add it in array like below:
etname.setFilters(new InputFilter[] {
new InputFilter.LengthFilter(maxLength), filter});
Finally the setFilter()
takes array of input filters, so in the array you create in setFilters()
should contain all the input filters.
Upvotes: 14