The getallviewsrecursive does a good job of iterating through the views, but how do you access them?
I have a panel with a scrollview. Within that scrollview I have programmatically added panels with two labels and an edit text. There are n panels that I need to parse and generate a comma separated long string with the values.
I have been struggling with the proper way to access the text within the edittext views . My parent panel has a single button that fires an event where I am attempting to read all the edittext text values in and generate the string.
Thank you, Mac
I have a panel with a scrollview. Within that scrollview I have programmatically added panels with two labels and an edit text. There are n panels that I need to parse and generate a comma separated long string with the values.
I have been struggling with the proper way to access the text within the edittext views . My parent panel has a single button that fires an event where I am attempting to read all the edittext text values in and generate the string.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim i As Int
SCVConfig.Initialize(500)
Activity.LoadLayout("main")
Activity.LoadLayout("ConfigLayout")
Activity.AddView(SCVConfig,10%x,25%y,80%x,65%y)
For i = 0 To PanelNb - 1
Dim LabelScrollPos As Label
Dim LabelField As Label
Dim edgText As EditText
pnl.Initialize("pnlTest")
SCVConfig.Panel.Addview(pnl,0,5dip + i *PanelHeight,100%x,PanelHeight)
pnl.LoadLayout("ConfigScrollLayout")
For n = 0 To pnl.NumberOfViews - 1
pnl.GetView(n).Tag = i
Next
Dim lbl As Label
lbl = pnl.GetView(0)
lbl.Text = "Field " & i
'getview(1) is the editbox
lbl = pnl.GetView(2)
lbl.Text = ConfigLabelList.Get(i)
If (i Mod 2) = 1 Then
pnl.Color = Colors.DarkGray
Else
pnl.Color = Colors.Transparent
End If
Next
SCVConfig.Panel.Height = PanelNb*PanelHeight
B4X:
Sub ButtonConfigSend_click
Dim Packet As UDPPacket
Dim Data() As Byte
Dim n As Int
Dim b As Button
Dim txt As EditText
Dim ConfigString As String
Dim i As Int
pnl.Initialize("pnlTest")
pnl.LoadLayout("ConfigScrollLayout")
ConfigString = "CAL,1.0"
SCVConfig.Panel.GetAllViewsRecursive - 1
EditText Then
i = 0
For Each v As View In SCVConfig.Panel.GetAllViewsRecursive
If v Is EditText Then
i = i+1
txt = SCVConfig.Panel.GetView(v) '<----- Error is here, this does not work.
'If txt.Text
ConfigString = ConfigString & "," & txt.Text 'grab all the edittext and build config string
End If
Next
Data = ConfigString.GetBytes("UTF8")
LabelConfigString.Text = ConfigString
Try
For x = MinIPNum To MaxIPNum
Packet.Initialize(Data,"192.168.0." & x,UDPRegistrationPort)
UDPRegistrationSocket.Send(Packet)
Next
Catch
Log(LastException)
ToastMessageShow("Port 55556 Busy, Is Sharks open elsewhere?",False)
End Try
End Sub