Android Question Retrieving the TAG of a customview set in the designer

Aegis

Member
Hello
I'm having problems accessing the TAG property of a B4XSwitch set in the designer.

I load the layout containing the B4XSwitch and a few other labels onto a panel p
B4X:
Dim p As Panel
p.Initialize("ClvPanel")
p.Height=60dip
p.LoadLayout("swiftbutton")

Then, i iterate on thepanel in order to retrieve and examine all the views (the TAG helps me differentiate between them)
B4X:
For Each v As View In p.GetAllViewsRecursive
    If v Is Label Then
        Log("--->label  "&v.Tag)
        Dim l As Label = v
          'do stuff with the label            
    Else If v Is Panel Then
         Log("--->panel  "&v.Tag)
         '....?
    end if
next

As expected, the b4xSwitch is retrieved as Panel, but v.tag is just the .ToString (guess because the panel is just a container and has to tag); The tag i set in the designer is actually inside v.mtag.tag

How to programmatically retrieve it?
And once done, how can i access the value property of the switch and manipulate it?


Thanks alot for your time, and stay safe.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. I recommend you to get used to B4XView. It is cross platform and is easier to work with.
2. You are loading the layout to a zero height panel. This is a mistake.
B4X:
Dim p As B4XView = XUI.CreatePanel("ClvPanel") 'only set the event name if you plan to handle the touch event
p.SetLayoutAnimated(0, 0, 0, 100dip, 60dip)
p.LoadLayout("SwiftButton")

For Each v As B4XView In p.GetAllViewsRecursive
  If v.Tag Is B4XSwitch Then
    Dim s As B4XSwitch = v.Tag
    Dim tag As String = s.Tag
  End If
Next
 
Upvote 0
Top