Android Question Is there TextField has property while keypress as currents numbers

Theera

Well-Known Member
Licensed User
Longtime User
I 'm looking for TextField has property while keypress as currents numbers .i.e.
if I need to input 10000 ,it will be shown while keypress is 10,000 (which is differ to B4XFormatter) .When I press backspace available to be 100 ,the comma will be disappeared. If I press 1000 ,it will be shown again 1,000
 

Theera

Well-Known Member
Licensed User
Longtime User
I 'll try it,Thank you for guide line.
 
Upvote 0

emexes

Expert
Licensed User
I 'll try it

Here's something to start with šŸ» no guarantee, but seems to work as you wished šŸ†

B4X:
Private Sub TextField1_TextChanged (Old As String, New As String)
  
    Dim GroupingChar As Char = "," 
  
    Dim GroupedNew As String = ""
    For I = New.Length - 1 To 0 Step -1    'scan and group digits from right to left
        Dim Ch As Char = New.CharAt(I)
        If "0123456789".Contains(Ch) Then    'if Ch is a digit
            If GroupedNew.Length <> 0 Then
                If (GroupedNew.Length Mod 4) = 3 Then    'if we have full group of three digits
                    GroupedNew = GroupingChar & GroupedNew
                End If
            End If
          
            GroupedNew = Ch & GroupedNew
        End If                 
    Next

    If New <> GroupedNew Then
        Dim CursorPos As Int = TextField1.SelectionStart - New.Length + GroupedNew.Length
        TextField1.Text = GroupedNew
        TextField1.SetSelection(CursorPos, CursorPos)
    End If

End Sub
 
Last edited:
Upvote 0
Top