Android Question EditText manipulate text as entered - Solved

padvou

Active Member
Licensed User
Hi.
If I want an EditText to add a "-" after the first two digits, while the user enters numbers:
for example:
typed EditText shows
1 1
2 12
3 12-3
4 12-34
5 12-345
6 12-3456

Can this be done?
 

padvou

Active Member
Licensed User
Here's what I came up with:
B4X:
Sub EditText1_TextChanged (Old As String, New As String)

If Old.Length<New.Length Then
    If Old.Length=2 Then
        New=Old.SubString2(0,2) & "-"
        EditText1.Text=New
        EditText1.SelectionStart=3
    End If
End If
   
End Sub
 
Top