B4J Question Identifying dynamic layout controls

I wish to add multiple copies of a layout in a pane:

B4X:
Sub Process_Globals

   Private Pane1 As Pane
   Private MultiPane As Pane
   Private MultiText As TextField
   
   Private SelectionTable(25) As Pane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   ...

   SelectionTable(0).Initialize("")
   SelectionTable(0).LoadLayout("MultiLayout")
   Pane1.AddNode(SelectionTable(0), 0, 0, 300, 100)

   SelectionTable(1).Initialize("")
   SelectionTable(1).LoadLayout("MultiLayout")
   Pane1.AddNode(SelectionTable(1), 0, 100, 300, 100)
   
   MainForm.Show
End Sub

The layout might contain 10+ controls.

The problem is I then need to identify events fired from (in this example) TextFields within the layout.

I can see from the TicTacToe example that I can use Sender to identify the control, but in order to identify where in the array it is I need to set either a Tag for each control in the Layout, or ideally a Tag on the control's parent pane (so I can have multiple controls identified by one Tag)

Unfortunately I can't work out how to set a Tag on the Layout's pane once loaded, or how to get to the control's parent in order to read the Tag.

Can someone please point me in the right direction, or at the appropriate documents?
 
That glee was short lived...

GetAllViewsRecursive gives me the Node, but if I want to change the text of a control, how do I get access to it from the Node?
 
Upvote 0
I now know how to get the data from the node, but only once it's been cast to the right type.
So my next question is, how do I query the node to find out which control it is so I can cast it correctly? Do I have to just go by index?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are many ways to do it.

Lets say that there are two buttons named Button1 and Button2 in the layout:
B4X:
Sub Process_Globals
 Private Button1, Button2 As Button
End Sub

Sub AppStart(...)
 'now we load the layout 50 times
 For Each p As Pane In MyPanes
  p.LoadLayout("LayoutWithTwoButtons")
  p.Tag = CreateMap("Button1": Button1, "Button2": Button2) 'Button1 and Button2 will always point to the last button1 and button2 added
 Next

End Sub

Dim m As Map = SomePane.Tag
Dim Button1 As Button = m.Get("Button1")
 
Upvote 0
Top