Android Question panel.loadlayout, warnings and the chicken and the egg


Active Member
Licensed User

I'm using a customlistview loaded with custom panels I load with loadlayout.

I'm getting the well-known warning
Panel.LoadLayout should only be called after the panel was added to its parent. (warning #1001)

However, I don't know how to solve it. I'm having a problem with changing the loadlayout after the .Add, and here's why:

- I have a label on the panel.

- the height of the label is variable, and I set it after loading the panel's layout (since I have a Dim lblMyLabelNamedAsInTheLayoutFile As Label declared at Sub Globals, and then I do lblMyLabelNamedAsInTheLayoutFile.Height=iVariableHeight)

- The panel I add also has a variable height. lstCustomListView.Add(tmpPanel,iVariableHeight,objMyObject)

- The label and panel heights are calculated using StringUtils library. So, I have to have them declared in order to calculate the height I need.

- So, if I move the lstCustomListView.Add before the LoadLayout, I get rid of the warning but I have no height set.

- I've tried to Add the panel with 0 height and change it later, but it has no effect on the UI.

- Also, I've think of manually initializing the label, but I remember reading "YOU SHALL NOT INITIALIZE VIEWS DECLARED IN THE LAYOUT" (or something like that). Besides, If I do this, I loose the ability to use the layout as a template so I don't have to code fonts sizes, types, etc.

- Using an auxiliary label feels the same since I also have to mantain the font properties by code If I decide to change them.

HELP!!!! hahaha

Thank you very much!


Active Member
Licensed User
Hi Erel, thank you very much for your answer!

Yes, I'm using a lot of anchors and scales, that's one of the reasons I'm using a layout file... and the script seems not to be working and I didn't wanted to ask about that until I solve the waring issue first; It didn't occured to me that both issues were related.

I'll try the auxiliary panel workaround and I'll get back tomorrow.

Thank you very much!!
Upvote 0