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?
I wouldn't have used TextChanged event for that task. Consider creating a simple "numpad" and handle the text input yourself. You should set the EditText InputType to none.
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
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.