xky Member Licensed User Longtime User Feb 7, 2013 #1 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. Code: 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: Feb 7, 2013
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. Code: 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
Erel B4X founder Staff member Licensed User Longtime User Feb 7, 2013 #2 See this tutorial: Tick-Tack-Toe: working with arrays of views Upvote 0
Informatix Expert Licensed User Longtime User Feb 7, 2013 #3 xky said: 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. Code: 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 Click to expand... 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 said: 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. Code: 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 Click to expand... 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.
thedesolatesoul Expert Licensed User Longtime User Feb 7, 2013 #4 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. Upvote 0
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.
Informatix Expert Licensed User Longtime User Feb 7, 2013 #5 thedesolatesoul said: You cant add a handler in runtime. Click to expand... Yes you can with the reflection library (SetOnClickListener), but it's useless here. Upvote 0
thedesolatesoul said: You cant add a handler in runtime. Click to expand... Yes you can with the reflection library (SetOnClickListener), but it's useless here.
thedesolatesoul Expert Licensed User Longtime User Feb 7, 2013 #6 Informatix said: Yes you can with the reflection library (SetOnClickListener), but it's useless here. Click to expand... You are correct, I forgot about that. EDIT: Though what I meant was the 'event sub' cannot be added at runtime. Upvote 0
Informatix said: Yes you can with the reflection library (SetOnClickListener), but it's useless here. Click to expand... You are correct, I forgot about that. EDIT: Though what I meant was the 'event sub' cannot be added at runtime.
xky Member Licensed User Longtime User Feb 7, 2013 #7 Thanks for all Code: 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
Thanks for all Code: 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.
Erel B4X founder Staff member Licensed User Longtime User Feb 7, 2013 #8 The prefix can be any name you want (assuming that it matches the EventName parameter). The second part of the name determines the event. Upvote 0
The prefix can be any name you want (assuming that it matches the EventName parameter). The second part of the name determines the event.