Problem with SelectAll on Focus with EditText

William Hunter

Active Member
Licensed User
Longtime User
I am trying to have the contained text selected when an EditExt has focus. I have searched the forum and have found recommendations on how to do this. The problem I am having is that in the three test examples below, each will perform the SelectAll function I need in Android V2 (Froyo), but will not do so in Android V4 (ICS). I only have the two devices for testing.

I have run out of ideas as to how this might be done. If anyone has had success in doing this across the various versions of Android, I would greatly appreciate their help in resolving my dilemma.

Best regards :sign0085:

B4X:
' test example one
Sub EditOne_FocusChanged(HasFocus As Boolean)
   If HasFocus = True Then
      EditOne.SelectAll
   End If
End Sub
' *********************************************
' test example two
Sub EditOne_FocusChanged(HasFocus As Boolean)
   If HasFocus = True Then
      EditOne_Click
   End If
End Sub

Sub EditOne_Click    'if in focus    
   EditOne.SelectAll
End Sub
' *********************************************
' test example three
Sub EditOne_FocusChanged(HasFocus As Boolean)
   If HasFocus = True Then
      EditOne_Click
   End If
End Sub

Sub EditOne_Click    'if in focus    
   CallSubDelayed(Me, "EditOne_SelectText")
End Sub

Sub EditOne_SelectText
   EditOne.SelectAll
End Sub
 

William Hunter

Active Member
Licensed User
Longtime User
Put this code in EditOne_SelectText:
B4X:
DoEvents
EditText1.SelectAll
DoEvents
EditText1.SelectAll

Thank you Erel. You have resolved the issue, with a double hitter. Now, two of us are back on track.

Best regards :icon_clap:
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Simil problem to select all text with autocompletation control

i have a autocompletation button, one command button and one gridview.

I cant' dovents in SELECTTEXT event because this event there are not supported.

The focus allways are in a autocompletation control, consequently a can't to this in the FOCUSCHANGED event.

I think to put a textbox to send focus to this control and before do selectall in focuschanged (incluying doevent), but this is not a correct programation for me.

some idea?
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
sorry, not gridview is a webview.

other idea:
send focus to a webview? but this is not posible (i think).
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
FOCUS SETFOCUS NOT IS RequestFocus

Solved.
I know the method RequestFocus.
Send focus to WebView and then the user do click (control get focus), i do this:

Sub SelectText
DoEvents
ACT.SelectAll
DoEvents
ACT.SelectAll
ACT.RequestFocus
End Sub

Act is: Dim ACT As AutoCompleteEditText

and when the the user do in search FIND, then send focus to a WebView,
and sending focus, the keypad are CLOSED!
 
Upvote 0
Top