Android Question How can I get the current EditText View name?

RodM

Member
Licensed User
Hello to all! It's my first post here in this wonderful community!

I'm trying B4A for the first time and I have a novice question:
When I press a button, I need to know the EditText where the focus is currently.
How can I get its name? Is there some kind of "ActiveViewName" property or some other way?

Can anybody help me or even tell me where I can find the answer?
Thanks.
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello and welcome to the forum,
The very simplest way is to use the Views Tag. You can place the views name in the Tag and then read the Tag information (in your case the views name) when you click on the button.

There are more complicated ways to get the views name, but as you are a beginner I would say to learn the basics before jumping in with the sharks ;)


Enjoy...
 
Upvote 0

RodM

Member
Licensed User
Hello and welcome to the forum,
The very simplest way is to use the Views Tag. You can place the views name in the Tag and then read the Tag information (in your case the views name) when you click on the button.

There are more complicated ways to get the views name, but as you are a beginner I would say to learn the basics before jumping in with the sharks ;)


Enjoy...

Thank you very much for your help, Peter!

I tried to follow your suggestion but, as you said, I'm a beginner and don't know how to use tags properly :) .

So I solved my problem by creating an object called CurrentTextField and then, when the focus change for any EditText view, I set CurrentTextField = edtText1 (for example), and when the button is clicked I can finally change some properties by manipulating the CurrentTextField object.

B4X:
Private Sub edtText1_FocusChanged (HasFocus As Boolean)
    If HasFocus = True Then CurrentTextField = edtText1
End Sub

Private Sub btnClear_Click
' Clear current text field contents.
    CurrentTextField.Text = ""
End Sub

It worked this way!

(learning a lot!!)

Thank you again.
 
Upvote 0
Top