I want to make the EditText accept only two decimals. If for example I put 23.89, do not let me add another decimal.
I want to make the EditText accept only two decimals. If for example I put 23.89, do not let me add another decimal.
what you should do is create an InputFilter like this:
editText.setFilters(new InputFilter[]{new InputFilter() {
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
int indexPoint = dest.toString().indexOf(decimalFormatSymbols.getDecimalSeparator());
if (indexPoint == -1)
return source;
int decimals = dend - (indexPoint+1);
return decimals < 2 ? source : "";
}
}
});