java minma_java – android edittext minmum和最大值

我正在开发一个

Android应用程序..实际上我需要设置一个editext条目的最小值和最大值我的最小值是18,最大值是65.I做了这个的确切代码

package com.test;

import android.text.InputFilter;

import android.text.Spanned;

public class InputFilterMinMax implements InputFilter {

private int min, max;

public InputFilterMinMax(int min, int max) {

this.min = min;

this.max = max;

}

public InputFilterMinMax(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 {

int input = Integer.parseInt(dest.toString() + source.toString());

if (isInRange(min, max, input))

return null;

} catch (NumberFormatException nfe) { }

return "";

}

private boolean isInRange(int a, int b, int c) {

return b > a ? c >= a && c <= b : c >= b && c <= a;

}

}

EditText et = (EditText) findViewById(R.id.myEditText);

et.setFilters(new InputFilter[]{ new InputFilterMinMax("1", "12")});

我只从这个网站获得此代码…

Is there a way to define a min and max value for EditText in Android?

实际上这对于1到12之间的值,并且对于该值它工作正常,但是当我改变我的值18和45时它不起作用…任何人都可以帮助我…我必须为此做什么改变. ..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值