In my app, the user is able to enter a dollar amount in a text field. The thing is, I need the input to adapt to the final number as they enter the digits, without actually entering the decimal point. The best way to explain this is with an example:
Suppose the user starts off with an EditText field which contains this:
.
The user wants to enter $12.53 into the field (i.e. the digits 1,2,5,3). Then he/she starts by entering 1, and the field should look like this:
.1
Then:
.12
Next:
1.25
Finally:
12.53
So as you may notice, the decimal places itself accordingly as the numbers are inputted. Is it possible to do this as the numbers are being entered? Thanks.
Yes, this is quite possible, even you don't have to manage
"$"
anddecimal
separately.Below is simple
EditText
which is manipulated byTextWatcher
:And if you require to know how
EditText
should be created inxml
, have this :This is an old question, but perhaps, it's better to be answered:)