Problem with EditText.InputType

chfajardo

Member
Licensed User
Longtime User
Erel,

I am having problems with InputType.
The code below works great in some devices, and in other devices it clears the EditText1.Text property when i change the EditText1.InputType.
This sub is used to alter the keyboard input type without user intervention.
The value to be entered is a vehicle´s plate, like ABC1234.
So, whe i am using the keyboard, after the 3rd character, the inputType is changed and the keyboard is changed to numeric.

Here is the code i´m using:


Sub EditText1_TextChanged (Old As String, New As String)
If(New<>"") Then
If(EditText1.Text.Length=3) Then
EditText1.InputType = EditText1.INPUT_TYPE_NUMBERS
Else If (EditText1.Text.Length<3) Then
EditText1.InputType = EditText1.INPUT_TYPE_TEXT
End If
If Old.Length=7 Then
New = Old
EditText1.Text = Old
End If
End If
End Sub


Any idea of what is happening?

Thank you in advance,

Carlos H. Fajardo.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [ code ] [ /code ] tags (without spaces) when posting code.

Your code is problematic as it changes the input type inside the TextChanged event. This can interfere with the way EditText work. You can try to move this code to a different sub and call CallSubDelayed to execute it.

Note that such "filters" are usually quite annoying to the user. The user might want to delete a character and enter a new one. Your filter will not allow it.
 
Top