How to add handler in runtime ?

xky

Member
Licensed User
Longtime User
If I create some EditText in run time, how can i get their events? Such as Focus_Changed.
in the code DataLine is a list.
B4X:
Sub Button2_Click
   Dim ET As EditText
   ET.Initialize("ET")
   Activity.AddView(ET,0,120+DataLine.Size*65,100%x,60)
   ET.Text="New" & (DataLine.Size+1)
   DataLine.Add(ET)
End Sub
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
If I create some EditText in run time, how can i get their events? Such as Focus_Changed.
in the code DataLine is a list.
B4X:
Sub Button2_Click
   Dim ET As EditText
   ET.Initialize("ET" & (DataLine.Size+1))
   Activity.AddView(ET,0,120+DataLine.Size*65,100%x,60)
   ET.Text="New" & (DataLine.Size+1)
   DataLine.Add(ET)
End Sub

You have to declare a generic handler:
ET_Click

In this handler, you get the sender (which EditText triggered the event):
Dim edt as EditText = Sender

If you want to store DataLine.Size+1, you can use the Tag property of the EditText.
 
Upvote 0

xky

Member
Licensed User
Longtime User
Thanks for all
B4X:
Sub ET_FocusChanged (HasFocus As Boolean)
   Dim Etxt As EditText 
   Etxt=Sender
   If Etxt.Tag<>"" Then
      If HasFocus Then
         If Etxt.Text.SubString2(0,3)="New" Then Etxt.Text=""
      Else
         If Etxt.Text="" Then Etxt.Text="New" & Etxt.Tag 
      End If
   End If   
End Sub

Here's the code, it successfully handles 2 event (Lost and Get Focus of 2 EditText), it's great.
I just understand the name of sub is important and must correct, not as in VS2012, it can use any name I want.
 
Upvote 0
Top