How do I determine which edittext has focus?

seskindell

Active Member
Licensed User
Longtime User
Is there a way I can determine which edittext control has focus when I press a button?

Would I somehow use the .tag field of the edittext control to determine this?

Thank you for any help you can provide.

- Steve
 

kickaha

Well-Known Member
Licensed User
Longtime User
Dim a global variable (lets call it EditFocus) as an EditText.

Generate "FocusChanged" events for the EditTexts you want to monitor.

In the FocusChanged event have these lines
B4X:
If HasFocus Then 
EditFocus = Sender
Else
EditFocus = Null

Then you have a pointer to the EditText that has the focus, it will be Null if none of them have focus.

If the program doesnt use the EditText events for anything else you can set the event name to be the same on all the EditTexts and just have the one FocusChanged event.
 
Upvote 0

artiechappie

Member
Licensed User
Longtime User
Hi,

Can you elaborate on this as I have a similar problem - I have 6 EditText fields and I need to determine which one has focus?

I am a recent "newbie" on this so any help would be appreciated.

I have "Dim"ed the EditFocus as an EditText as you suggest but how do I pass the current EditText to the Event Handler and this is the Event Handler I created:

Sub TextBox1_FocusChanged (HasFocus As Boolean)

If HasFocus Then
EditFocus = Sender
Else
EditFocus = Null
End If

End Sub

Help please??

Many thanks in advance
 
Upvote 0
Top