Android Question FloatLabeledEditText set cursor position

fred-han

Member
Licensed User
Is there a way to set the cursor in the field at a defined position like "MaskedEditText"-Lib do?

I want to create a field with some kind of mask and the way "MaskedEditText" do is quit good an easy, but the style of the field is not the same as "FloatLabeledEditText" and i want to have always the same look.

Any suggestions? Perhaps is it possible to extend the B4XFloatText.b4xlib?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim et As EditText = B4XFloatTextField1.TextField
'work with et.SetSelection

It is not simple to create a "mask feature" and unless it works perfectly then it is likely to cause more harm than good. In many cases it is simpler to check whether the input is valid when the focus is lost or when the user clicks on a button.
Another option is to handle the TextChanged event and set the border to be red when the input is invalid.
 
Upvote 0

fred-han

Member
Licensed User
I want to create an input that looks like 09/2012 (month/year) that looks the same way as BFTF.. When the user enters 2 signs, i add the "/" and he can type the rest.
I tried the following:
B4X:
Sub ed_fz_tuev_TextChanged (Old As String, New As String)
   If New.Length = 2 Then
       New = New & "/"
       ed_fz_tuev.Text = New
       Dim et As EditText = ed_fz_tuev.TextField
       et.SelectionStart = 3
   End If
  
End Sub

That works .... but if i use the backspace from keybord, the "/" sign would not be deleted. I think "SelectionStart" is the reason ...
How can i manage this?

Is there a way for me to add the properties "SelectionStart" and "SelectionEnd" to B4XFloatTextField.bas ??
 
Upvote 0

fred-han

Member
Licensed User
Okay i will use the internal access to EditText.

But the other problem is, that the "Backspace" from keyboard stops at the position i have set with "SelectionStart".
What can i do to get the cursor delete the signs beyond this position?
 
Upvote 0
Top