Hi all,
I'm working on custom view which has an EditText/TextField at its core.
I'd like to expose a SetFocus function so to give the programmer control on this respect.
When control receives focus it should select and highlight all the text it holds.
So far the best way I found is the following (simplified code):
The above causes a double RequestFocus (intentional in order to obtain the "selectAll" effect).
I tried with JO and several other ways to no avail.
Can you suggest a different approach, but yet valid in a XUI/B4X context? TIA
I'm working on custom view which has an EditText/TextField at its core.
I'd like to expose a SetFocus function so to give the programmer control on this respect.
When control receives focus it should select and highlight all the text it holds.
So far the best way I found is the following (simplified code):
B4X:
Private tf As B4XView ' defined in Class_Globals
'tf initialized in DesignerCreateView by means of a locally dimmed EditText or TextFiled var
'Changes view's focus and eventually calls corresponding event in calling module (if set).
'If current text doesn't pass the matching-pattern test, focus is forced to stay unless LetFocusOut permits it anyway
Private Sub tf1_FocusChanged(HasFocus As Boolean)
Dim okmsg As Boolean = True
If Not(HasFocus) Then
If Not(LetFocusOut) Then
If Not(Regex.IsMatch(mpattern, tf.Text)) Then
tf.RequestFocus
okmsg = False
End If
End If
Else
tf.RequestFocus 'this is the "second" call to RF, needed to have the selectall effect
End If
If okmsg And SubExists(mCallBack, mEventName&"_FocusChanged") Then CallSub2(mCallBack, mEventName&"_FocusChanged", HasFocus)
End Sub
Public Sub setFocus
tf1_FocusChanged(True)
End Sub
The above causes a double RequestFocus (intentional in order to obtain the "selectAll" effect).
I tried with JO and several other ways to no avail.
Can you suggest a different approach, but yet valid in a XUI/B4X context? TIA