Android Question Number Text input from Right side like Calculator

DeviousD

Member
Licensed User
Longtime User
Hi Guys,

I have been scouring the forum to see if i can find a quick snippet of code but with no success. being under pressure also does not help...

I need to have an editbox start with "0000.00" and when a users enters a value, the numeric value needs to start on the right and fill in towards the left like this:

editbox is set to accept DECIMAL_NUMBERS and its start value is 0000.00

"0000.00"
"0000.01"
"0000.12"
"0001.23"
"0012.36"

I have tried to multiple the value by 10 each time, possibly moving the decimal point 1 over but i my app shuts down and closes even in a try catch

then i tried to use the numberformat functions on the textchange value, same diffs,
my app shuts down and closes even in a try catch


Any suggestions...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
my app shuts down and closes even in a try catch
My guess is that your code in TextChanged event created a stack overflow.

As a general rule it is a bad user experience to change the text while the user types. A better approach is to change the text once the user finished writing. It is also simpler to do.
 
Upvote 0

DeviousD

Member
Licensed User
Longtime User
Thanks for the feedback Erel.

The Client wants to see it interactively updating , hence the use of TextChanged event

This is for an APP here in Sunny South Africa and the target user has used a piece of hardware that worked this way... so i'm forced to simulate same...
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
try this:

B4X:
Sub Process_Globals
        '...
    Dim txtchn As Boolean
End Sub


Sub TextField1_TextChanged (Old As String, new As String)
    If txtchn = False Then
        txtchn = True
        Dim str As String = Old.Replace(".","") & new
        change_txt(str)
    Else
        txtchn = False
    End If
End Sub

Sub change_txt(nr As Double)
    TextField1.Text = NumberFormat2(nr/100,5,2,2,False)
    TextField1.SelectAll
End Sub

But i agree with @Erel, better put a label and on click event use your own numpad (will be much easier)
 
Last edited:
Upvote 0
Top