Copyright (c) 2013, Nelspike
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Red...
If you think the Android project BusTicketer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package bus.ticketer.filters;
//fromwww.java2s.comimport android.text.InputFilter;
import android.text.Spanned;
publicclass MonthInputFilter implements InputFilter {
privateint min, max;
public MonthInputFilter(int min, int max) {
this.min = min;
this.max = max;
}
public MonthInputFilter(String min, String max) {
this.min = Integer.parseInt(min);
this.max = Integer.parseInt(max);
}
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
try {
String newVal = dest.toString().substring(0, dstart) + dest.toString().substring(dend, dest.toString().length());
newVal = newVal.substring(0, dstart) + source.toString() + newVal.substring(dstart, newVal.length());
int input = Integer.parseInt(newVal);
if (isInRange(min, max, input))
return null;
} catch (NumberFormatException nfe) { }
return"";
}
privateboolean isInRange(int a, int b, int c) {
return b > a ? c >= a && c <= b : c >= b && c <= a;
}
}