Here is my current code which only allows integers. I want to restrict the user even more to only allow 0s and 1s. I wish it were as simple as !Character.isBinary(..)
, but it isn't. How can I manipulate the start and end parameters to accomplish this?
final InputFilter binaryOnlyFilter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for ( int i = start; i < end; i++) {
if (!Character.isDigit(source.charAt(i)) && source.charAt(i) != ' ') {
return "";
}
}
return null;
}
};