B4J Question dynamic components and events

madru

Active Member
Licensed User
Longtime User
I looked today for the 1st time into dynamically created B4J components.

I am wondering how to deal with those, how can I write to such component or can I receive events?
e.g.

I have a TabPane where I have a tableview and a button on - created via the designer , this TabPane is loaded via
B4X:
 TabPane1.LoadLayout("mytabLayout","Tab")

if I like to write to a 'static' Tableview I use this for example
B4X:
Dim Row(5) As Object
Row(0)=name.Trim
Row(1)=gen.Trim
Row(2)=WrapLabel(lbl, "CENTER_RIGHT")
Row(3)=c
Row(4)=getDateTime
TableView1.Items.Add(row)

but how do I know the tableview if doing it dynamically?
same for the button?

THX
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hello!

Every pane including the mainform.rootpane has the function: pane.getallnodesrecursively (something like that) you can use the tag or other methods to get your desired table.

And wheter it is dynamic or static can assign/share the event. You only need the sender function to identify them
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Not sure if I 100% understand what you are trying to do
Creating tableviews
B4X:
Dim mtv As TableView
...
mtv.Initialize("mtv") ' prefix for events
mtv.SetColumns(Array("col1","col2","col3",...))
mtv.SetColumnWidth(0,100) ' set col widths or else they are collapsed
mtv.SetColumnWidth(1,100)
mtv.SetColumnWidth(2,100)
...
mtv.Items.Add(...) ' add the items as normal
??.RootPane.addNode(mtv,0,0,200,300) ' add to parent node
'or
??.addNode(...) 'etc
 
Last edited:
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi Enrique, Daestrum,

thx for getting back to me.

I still confused how to consume the events from an item on a tab or set something.

I attached a skeleton project with a dynamic added(multiple) tab with a button and a tableview, can you teach me how to use them?

still confused how that works :(
 

Attachments

  • testtab.zip
    3.4 KB · Views: 238
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi Enrique,

thank you very much I missed GetAllViewsRecursive completely ....

a last question I have on this, is this the right way to put an identifier to a component or can it be done easier without looping through every component?

B4X:
Sub addNewTab_MouseClicked (EventData As MouseEvent)
    tabCount=tabCount+1
    TabPane1.LoadLayout("tabLayout","Tab : "&tabCount)
    For Each v As Node In MainForm.RootPane.GetAllViewsRecursive
        Log(v)
        If v IsTableViewThen
            If v.Tag ="" Then
                v.Tag = my_unique_tag
            EndIf
        EndIf
    Next
EndSub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If you only want to change TableView objects then yes. Kind of (you need to cast v to a TableView first...
B4X:
dim tv as TableView = v

complete
B4X:
        If v Is TableView Then
          dim tv as TableView = v
            If tv.Tag ="" Then
                tv.Tag = my_unique_tag
            EndIf
        EndIf
 
Upvote 0
Top