I have an EditText
box which have to allow user to enter upto 7 numbers and two decimal places. After entering seven digits,it should not allow to add one more digit but i may allow upto 2 decimal places. I use a decimal filter for 2 decimal places and this code in XML
android:maxLength="7"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
But EditText
is allowing to enter
8 digits. How can this be solved?
You can enhance it when using Android databinding like this:
Define custom binding adapter:
Add attributes to EditText:
and it will automatically set the input filter for the edittext
Try this under onCreate
this anywhere in your program
You can user this input filter to solve your problem. To set filter:
If you don't want to limit digits before or after dot just put
Integer.MAX_VALUE
, to disable max value limit useDouble.POSITIVE_INFINITY
.You can use this filter for text fields where you enter numbers or numbers and text.
I hope it helps you.
You can user this input filter to solve your problem. To set filter: For 4 digits and Two Decimal points