Android Question editText.Text all lower case

nikolaus

Member
Licensed User
Longtime User
Hi, is there a way to force an editText to allways show lower case characters?

Depending on keyboard and its settings the first char may be a capital, but I want all input to be lower case. Didn't find a solution with InputType.
 

stevel05

Expert
Licensed User
Longtime User
I haven't tested it exhaustively, but something like this should work:

B4X:
Sub Process_Globals
       Private TextChanged As Boolean
End Sub

Sub EditText1_TextChanged (Old As String, New As String)
   'If it's been changed, then this sub will be called again, so ignore the next call
    If TextChanged Then
        TextChanged = False
        Return
    End If
    TextChanged = True
    Dim Pos As Int = EditText1.SelectionStart
    EditText1.Text = New.ToLowerCase
    EditText1.SelectionStart = Pos
 
End Sub
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hi, is there a way to force an editText to allways show lower case characters?

Depending on keyboard and its settings the first char may be a capital, but I want all input to be lower case. Didn't find a solution with InputType.
Use the filter of my Masked EditText library to convert any character to its lowercase version. It's much better than trying to alter the result with the TextChanged event.
 
Upvote 0

nikolaus

Member
Licensed User
Longtime User
Steve, thank you for your help. I cannot do it this way as I heavily use editText_TextChanged already. I was looking for a way to change editText behaviour directly like it can be done with InputType.

Informatix, your Lib seems to be what I was looking for. I will check it out and give feedback. This will take some time, I am still learning..
 
Last edited:
Upvote 0
Top