Currency Input Question

dank

Member
Licensed User
Longtime User
Hi. I have a client that wants currency input like this:

If the user enters a "1" in an edittext view, the text should be .01.
If the user then enters a "2", the text should show .12.
If the user then enters a "3", the text will now be 1.23, and so forth.

I've been working with TextChanged but haven't been successful thus far. Does anyone have any ideas?

Thanks in advance!
 

mc73

Well-Known Member
Licensed User
Longtime User
Perhaps you could use something like this, though I think that Erel's proposal is more clear.
B4X:
Sub yourTextBox_TextChanged (Old As String, New As String)
If Old=New Then
Return
Else
Dim tempString As String
tempString=New.Replace (".","")
Dim tempval As Double 
tempval=tempString/100
yourTextBox.Text=tempval
yourTextBox.SelectionStart =yourTextBox.Text.Length
End If
End Sub
 
Upvote 0

dank

Member
Licensed User
Longtime User
Thanks for your replies. The custom keyboard seems like the best solution, but I don't have time to implement it right now.

I came up with another (just okay) solution. I use the EditText for editing and a Label to display the result. I partially hide the edit box so the user notices only the label text.

One thing, though: how can I force the cursor at the end of my text in the edittext view when it gets focus? That way, editing will be much easier for the user.

Thanks again!
 
Upvote 0
Top