我在開發一個android應用程序..實際上我需要設置editext條目的最小值和最大值,我的最小值是18,最大值是65.我做了這個確切的代碼android edittext minmum和最大值
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是不工作......任何人都可以請幫助我..我必須做什麼改變...
嘗試登錄該值或嘗試調試MMODE。 –
你有沒有嘗試從itsrajesh4uguys在你給的鏈接答案...該解決方案是好的,爲我工作... –
感謝jeet評論...讓我試試.. – user2223317