B4J Question [SOLVED] [ABMaterial] Get components inside a tab control

mindful

Active Member
Licensed User
Hi all,

I have a page (Page) in which I add an ABMContainer (container1). Inside the container I add an ABMTabs control (tabs1) in which I add two tabs (tab1 and tab2).
*) I am adding the tabs1 control in a container (container1) because I need to animate it.

what is the best way to access the controls inside tab1 ?!

I do it like this now:
B4X:
Dim pc As ABMContainer = Page.Component("container1")
Dim tc As ABMTabs = pc.Component("tabs1")
Dim tp As ABMContainer = tc.GetTabPage("tab1")
dim inp1 as ABMInput = tp.Component("inp1")

Is there another way ?! I see that the id in the html file for the inp1 is tab1-inp1 but if I try to put it like this:
B4X:
dim inp1 as ABMInput = Page.Component("tab1-inp1")
It doesn't work it says: No component found with id tab1-inp1

And another question: Does anyone know what does ABM.CastABMComponent(com.ab.abmaterial.ABMaterial.CastABMComponent) do ?!
 

jayel

Active Member
Licensed User
Longtime User
B4X:
dim mypc as ABMContainer = page.Component("container1")
dim mytab as ABMTabs = mypc.Component("tabs1")
dim mytabcontainer as ABMContainer = mytab.GetTabPage("tab1")
Dim myinput as ABMInput = mytabcontainer.Component("inp1")
 
Upvote 0

mindful

Active Member
Licensed User
B4X:
dim mypc as ABMContainer = page.Component("container1")
dim mytab as ABMTabs = mypc.Component("tabs1")
dim mytabcontainer as ABMContainer = mytab.GetTabPage("tab1")
Dim myinput as ABMInput = mytabcontainer.Component("inp1")

Jayel this is how I do it right now. I just wanted to see if there is a quicker ...
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
Hi all,


Is there another way ?! I see that the id in the html file for the inp1 is tab1-inp1 but if I try to put it like this:
B4X:
dim inp1 as ABMInput = Page.Component("tab1-inp1")
It doesn't work it says: No component found with id tab1-inp1

And another question: Does anyone know what does ABM.CastABMComponent(com.ab.abmaterial.ABMaterial.CastABMComponent) do ?!

The above code will not work, my code will work !
 
Upvote 0

mindful

Active Member
Licensed User
The above code will not work, my code will work !

As you can see in #1 post your code is the same as mine (the one that I am using right now) which you are right It Works:
B4X:
Dim pc As ABMContainer = Page.Component("container1")
Dim tc As ABMTabs = pc.Component("tabs1")
Dim tp As ABMContainer = tc.GetTabPage("tab1")
Dim inp1 as ABMInput = tp.Component("inp1")

I just wanted to find out if there is another way to access a control inside another control. If you have many nested controls it's kind of hard to keep up and I saw that each control has a unique id in html and thought that we can take advantage of this thing, that is why I asked what does the CastABMComponent method do ...
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
This is the only way. ABMComponents have internally a lot more going on about IDs (Parent linkage, Arrays, etc). You can always write your own 'shortcuts'.

e.g.
B4X:
Sub GetInput(id as String) as ABMInput
   Dim pc As ABMContainer = Page.Component("container" & id)
   Dim tc As ABMTabs = pc.Component("tabs" & id)
   Dim tp As ABMContainer = tc.GetTabPage("tab" & id)
   return tp.Component("inp" & id)
End Sub

Dim myInput as ABMInput = GetInput(1)
CastABMComponent is a completely unrelated method. It works like you would 'cast' a string to a double, but for ABMComponents.

Cast a generic ABMComponent. You can use the ABMComponent.Type to find out what sort of component it is.
ABMComponent.Type is one of the ABM.UITYPE_ constants.

Example:
B4X:
Dim comp as ABMComponent = page.component("mycomp")
if comp.Type = ABM.UITYPE_LABEL then
    Dim lbl as ABMLabel = ABM.CastABMComponent(comp)
end if
Now you can use all methods or properties of the ABMLabel.
 
Upvote 0
Top