Android Question getallviewsrecursive - how do you access the nested views?

macsboost

Member
Licensed User
Longtime User
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.



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
Thank you, Mac
 

macsboost

Member
Licensed User
Longtime User
Thanks for the quick response, but I already am trying that. The issue lies with trying to retrieve the text value of the edit text views while in that loop.

Getview(v).text does not work.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hello everyone
reading the views, how do I read the type of view and his name?

For Each v As View In Activity.GetAllViewsRecursive

v Name?
v Type?

Next
thanks
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Hello everyone
reading the views, how do I read the type of view and his name?

You dont need the name! You have an reference to the object...

B4X:
For Each v As View In Activity.GetAllViewsRecursive
  if v is Button then
    dim vbutton as button =v
    ' now do whatever you want to to with this button.... Setting color, Text, position
  end if

PS: Erel already told that here in thread in post #4
 
Last edited:
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
hello DomManfred,
I saw, but I was looking for an alternative method is to see if Button / Text then, that seek to control his type. In this way, I have to make a list of all types of control.
thanks
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
hello DomManfred,
I saw, but I was looking for an alternative method is to see if Button / Text then, that seek to control his type. In this way, I have to make a list of all types of control.
thanks

Put all buttons in a list, put all labels in a list, and so on....
If you want to change buttons you can use your buttonlist, if you want to change labels you takte the labelslist, and so on...

What exactly you want archieve?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…