Android Code Snippet EditText Max Length

More shorter code compared to here

Example:
B4X:
Sub Globals   
    Dim txtPIN As EditText
End Sub

Sub txtPIN_TextChanged (Old As String, New As String)
    If New.Length > 6 Then
        txtPIN.Text = Old
        txtPIN.SelectionStart = Old.Length
    End If  
End Sub
 

aeric

Expert
Licensed User
Longtime User
It is better to use IME.SetLengthFilter.

Note that in your code you should use New.Substring2(0, 6) if you want to support paste actions.
Thanks Erel
 
Top