B4J Question B4XDialog, Create by Code

mw71

Active Member
Licensed User
Longtime User
Hello,

with the following code I create a Panel, 2 Labels and a ComboBox which are loaded into the Panel.
Unfortunately the positioning does not work. The two log outputs give me 0. This can't be right.
What am I doing wrong?

B4X:
Dim cld As B4XDialog
Dim pnl As B4XView = xui.CreatePanel("")

Dim spn As ComboBox
Dim lbl As Label
Dim lbl_band As Label

Dim retBands As List = rMap.Get("retBands")
Dim retZumBerg As String = rMap.Get("retZumBerg")
Dim retZumBerg_Call As String = rMap.Get("retZumBerg_Call")
Dim MultiCall As Boolean = rMap.GetDefault("MultiCall",False)

cld.Initialize(Root)
pnl.SetLayoutAnimated(0,0,0,300dip,400dip)

lbl.Initialize("lbl")
lbl_band.Initialize("lbl_b")
spn.Initialize("spn")


pnl.AddView(lbl,5dip,5dip, 200dip,80dip)
Log("1: " & lbl.Height)'<<-- returns 0

'2 Lines for test only
lbl.SetSize(200dip,80dip)
Log("2: " & lbl.Height)'<<-- also returns 0

pnl.AddView(lbl_band,5dip, 10dip + lbl.Height,200dip,40dip)
pnl.AddView(spn,5dip, lbl_band.Top + lbl_band.Height,Spinner1.Width,40dip)
lbl.TextSize=20
lbl.WrapText=True
lbl_band.TextSize=20

spn.items.Add("")

For i=0 To Spinner1.items.Size-1
    If retBands.IndexOf(Spinner1.items.Get(i))<0 Then spn.items.Add(Spinner1.items.Get(i))
Next

If spn.items.Size >=2 Then spn.SelectedIndex = 1


lbl_band.Text = Main.loc.LocalizeParams("txt_chk_SetUp3_FillzumBerg_BG",Array As String(Spinner1_Item))

lbl_band.Top = lbl.Height + 15dip
spn.Top =lbl_band.Top + lbl_band.Height + 5dip

Dim rs As ResumableSub = cld.ShowCustom(pnl, "Yes", "No","")


Wait For (rs) Complete (r As Int)
 

Daestrum

Expert
Licensed User
Longtime User
A lot of controls don't actually get a width or height until they have been rendered on screen.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It's a lot easier to create a layout and load it into the panel (after you've sized it). Provided the anchors are set correctly, it'll just work.

If you create global variables for the views contained in the layout, they will point to the views for the last time you loaded that layout.
 
Upvote 0
Top