Wish XUI Views supporting AddToParent method

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
There are times when I need to dynamically add UI elements based on user configuration and having an AddToParent(...) method in the various B4XViews would be much easier than having to create one layout for each needed individual control and then, load the specific layout, .SetLayout(...), etc. which also enforces the same name/event for the control each time which can be cumbersome if you need multiples on the same layout.
 

stevel05

Expert
Licensed User
Longtime User
B4xView has an AddView Method, is this not what you are looking for?
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Perhaps there is a method I can't find in the help, but this is the crux of the issue:
Example:
    Dim poText As B4XFloatTextField
    Dim poView As B4XView = poPan

    poText.Initialize(Me, "poText")
    ' poPan is the hosting panel for this control and is a plain Panel (e.g. Dim As Panel)
    poPan.AddView(poText, 10dip, 10dip, 100dip, 50dip)  '<--- types do not match error
    poView.AddView(poText, 10dip, 10dip, 100dip, 50dip) '<--- types do not match error
    ' I need something like the statement below as far as I can tell...
    poText.AddToParent(poPan, 10dip, 10dip, 100dip, 50dip)
I know how to work around this, by sizing a hosting panel, loading a layout etc. it would be nice if I didn't have to.
 
Last edited:

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
they are not designed to be added in code
Hence my post as a "wish", not a question ;)

If there is some underlying reason why an "AddToParent" method cannot be supported, that is understandable. If it is just "not designed" to do that, then I'll leave my "wish" post as is.
 

klaus

Expert
Licensed User
Longtime User
B4xFloatTextField is a custom view, they are not designed to be added in code. See this discussion: https://www.b4x.com/android/forum/t...omviews-in-code-doesnt-work.66674/post-421932
CustomViews can be added in the code if an AddToParent method is defined in the CustomViews code.
The discussion in the link in your post was my mistake, a real beginner's mistake.
I tried to add a CustomView like a B4J Node with
MainForm.RootPane.AddNode(btnTest3, 190, 200, 60, 40)
It must be be:
btnTest3.AddToParent(MainForm.RootPane, 190, 200, 60, 40)
The AddToParent method did exist in my KCButton CustomView, and this works.
 
Top