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
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 cant add a handler in runtime. You can create as many handlers while coding if you know how to.
The better solution is to use a single handler/event for all the edit texts and put the DataLine.Size+1 in the Tag. You can then check for the Sender and its Tag in the event sub.
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.