Android Question EditText manipulate text as entered - Solved

Discussion in 'Android Questions' started by padvou, Jun 2, 2015.

  1. padvou

    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?
     
  2. DonManfred

    DonManfred Expert Licensed User

    yes.
     
  3. padvou

    padvou Active Member Licensed User

    Thank you.
    I'll keep working on it.
     
  4. fixit30

    fixit30 Active Member Licensed User

    You should look at the TextChanged event of EditText
     
    padvou likes this.
  5. padvou

    padvou Active Member Licensed User

    Here's what I came up with:
    Code:
    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
     
Loading...