Sono in sviluppo di un'app Android .. in realtà ho bisogno di impostare un valore minimo e massimo per una voce editext il mio valore minimo è 18 e il massimo è 65. Ho fatto il codice esatto di questoandroid eittext minmum e valore massimo
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")});
ho avuto questo codice fro solo in questo sito ... Is there a way to define a min and max value for EditText in Android? in realtà questo per i valori compresi tra 1 e 12 e per quel valore si sta lavorando bene, ma quando ho cambiato per il mio valore 18 e 45 non è lavoro ... qualcuno può aiutarmi per favore ... quale cambiamento devo fare per questo ...
prova ad accedere i valori o cercare debugger mMode. –
hai provato la risposta da itsrajesh4uguys nel link che hai dato ... quella soluzione è buona e ha funzionato per me ... –
grazie jeet per aver commentato ... fammi provare .. – user2223317