B4J Question [ABMaterial] Get buttons tag

alienhunter

Active Member
Licensed User
Longtime User
Hi ,
i got a list with many buttons , and i want to get the tag of each button using same id just the tag is different in one click sub if this is possible .
I looked up in the forum and i could not find anything .
Since I try to make the ABM as a ERP I have to learn a lot

B4X:
    Dim butt1 As ABMButton
    butt1.InitializeFlat(page,"r" &serverli ,"","","STOP","red")
    butt1.UseFullCellWidth=True
    butt1.Tag=serverli
    servercount.Cell(1,4).AddComponent(butt1)
   
    Dim butt2 As ABMButton
    butt2.InitializeRaised(page,"s" &serverli,"","","START","green")
    butt2.UseFullCellWidth=True
    butt2.Tag=serverli
    servercount.Cell(1,5).AddComponent(butt2)

thanks AH
 

Attachments

  • buttonarray.JPG
    76.6 KB · Views: 276

alienhunter

Active Member
Licensed User
Longtime User
thank you
but i still do not get it sorry

B4X:
listserver.AddItem("H"& i, buildserverlist(....

Sub buildserverlist(id As String, icon As String...

Dim servercount As ABMContainer
servercount.Initialize(page,"containerx", "")

.....
servercount.Cell(1,4).AddArrayComponent(butt1,"button")


Sub button_Clicked(Target As String)
   Log(Target)
   Dim cont1 As ABMContainer = page.Component("containerx")
'   Dim xx As  ABMButton=cont1.Component(Target)
'   Dim xxd As String=xx.Tag
'   Log(xxd)

End Sub

i get this in the log
containerx-button0
No component found with id containerx

there is a list build with containers and inside the container are the buttons
so do i have to get the list from the page then the Contanier where the buttons are ?

thanks AH
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Here is an example with an array of ABMContainers, each with a label and a button. I've added some comments explaining it:

B4X:
...
' let's add 10 containers, each with a label and a button
For counter = 1 To 10
       Dim cont As ABMContainer
       cont.Initialize(page, counter, "")  ' <------- the id is just a number here
       cont.AddRows(1,False,"").AddCellsOSMP(2,0,0,0,6,6,6,0,0,0,0,"")
       cont.BuildGrid
     
       ' just like normal, we add a label with the name lbl (NO counter here, else our lables will be called lbl1 -> lbl10 and we just want lbl)
       Dim lbl As ABMLabel
       lbl.Initialize(page, "lbl", "Label " & counter, ABM.SIZE_H6, True, "")
       cont.Cell(1,1).AddComponent(lbl)
     
       ' just like normal, we add a button with name btn (NO counter here, else the events would be btn1_clicked -> btn10_clicked and we just want btn_clicked)
       Dim btn As ABMButton     
       btn.InitializeFlat(page, "btn", "", "", "Button " & counter, "")
       cont.Cell(1,2).AddComponent(btn)
 
       ' here we add the container, with prefix cont so we will get cont1 -> cont10
       ' the prefix 'cont' + the containers id, which is a number (counter)
       page.Cell(1,1).AddArrayComponent(cont, "cont")
Next
...

B4X:
' note: we can simply use btn_clicked here.  We'll use the target text to find out which button was clicked
Sub btn_Clicked(Target As String)
   Log(Target) ' will show contXX-btn where XX is 1 to 10
   Target = Target.Replace("-btn", "") ' remove the -btn part
   Dim cont As ABMContainer = page.Component(Target) ' now we can use the rest of the target as it now matches cont1 -> cont10
   Dim lbl As ABMLabel = cont.Component("lbl") ' we pick the lbl as normal
   Log(lbl.Text) ' logging the text to prove we are on the right container
End Sub

Getting the unique part out of the Target can be tricky sometimes. E.g. I have in an app of me an array of containers each with collapsable containers inside them and several components in each collapsable container. In that case I also had to use the ID (counter) on my collapsable container as the target returned was: _heading_cont01-lbledit (the outer container was not returned, just the collapsable heading container).

But the principle was the same:
B4X:
Sub lblEdit_Clicked(Target As String)
   Log(Target) ' _heading_cont01-lbledit
   Dim ID As String = Target.SubString2(13,15)
   Log(ID) ' 01
   ' my array container
   Dim MethCont As ABMContainer = page.Component("MethCont" & ID)
   ' my collapsable container within the previous container
   Dim Cont As ABMContainer = MethCont.Component("Cont" & ID)
   ' getting the label as normal from the collapsable container
   Dim lblType As ABMLabel = Cont.CollapsableHeading.Component("lbltype")
   ' let's print the text for proof
   Log(lblType.Text)
End Sub
 
Last edited:
Upvote 0

alienhunter

Active Member
Licensed User
Longtime User
Hi
thank you ... , i was so driven by something else i did not see this
"page.Cell(1,1).AddArrayComponent(cont, "cont")" , adding the container as array comp not the button
thank you very very much
my brain fa.t
AH
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Hi
thank you ... , i was so driven by something else i did not see this
"page.Cell(1,1).AddArrayComponent(cont, "cont")" , adding the container as array comp not the button
thank you very very much
my brain fa.t
AH
I know u mean... Simple addarrays on the page were (rather) easy. But when buried in a container... that was another level of understanding. Yet we eventually get it.

Logging the events and params from Page_ParseEvent goes a long way in helping you see what is being passed.


Sub Page_ParseEvent(Params As Map)
Dim eventName As String = Params.Get("eventname")
Dim eventParams() As String = Regex.Split(",",Params.Get("eventparams"))

Log("Page Parse Event: "&eventName&" - "&Params) ' include this on every page!!!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…