I want to define a min and max value for an EditText
.
For example: if any person tries to enter a month value in it, the value must be between 1-12.
this is my code max=100, min=0
xml
java
EditText ed = findViewById(R.id.txt_Mass_smallWork);
ed.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {`
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(!charSequence.equals("")) {
int massValue = Integer.parseInt(charSequence.toString());
if (massValue > 10) {
ed.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)});
} else {
ed.setFilters(new InputFilter[]{new InputFilter.LengthFilter(3)});
}
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});