Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.text.InputFilter;
- import android.text.Spanned;
- public class DoubleMinMaxFilter implements InputFilter {
- private double mDoubleMin, mDoubleMax;
- public DoubleMinMaxFilter(double minValue, double maxValue) {
- this.mDoubleMin = minValue;
- this.mDoubleMax = maxValue;
- }
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
- try {
- double input = Double.parseDouble(dest.toString() + source.toString());
- if (isInRange(mDoubleMin, mDoubleMax, input))
- return null;
- } catch (NumberFormatException nfe) { }
- return "";
- }
- private boolean isInRange(double a, double b, double c) {
- return b > a ? c >= a && c <= b : c >= b && c <= a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement