Android Question [Solved]How to code AddView B4XImageView in a CustomView?

Theera

Expert
Licensed User
Longtime User
In Non-B4XPages ,imgSwitch As ImageView
B4X:
    imgSwitch.Initialize("imgSwitch")
    mBase.AddView(imgSwitch, 0, 0, mBase.Width, mBase.Height)

,But in B4XPages, I have changed imgSwitch As B4XImageView (Using B4XViews library)
B4X:
    imgSwitch.Initialize(Me,"imgSwitch")
    mBase.AddView()      '<==How to code?
 
Solution
If, however, you want to create some Views in the project from code, you should know that you can do this with "native" Views, such as Button, Label, EditText, etc., but you can't do it with Custom Views; you'll always have to insert them into a Layout.

https://www.b4x.com/android/forum/t...ew-here-s-how-to-add-programmatically.118037/

For B4XImageView there is an exception: you can use XUIViewsUtils.CreateB4XImageView
B4X:
Dim imgSwitch As B4XImageView
imgSwitch = XUIViewsUtils.CreateB4XImageView
mBase.AddView(imgSwitch.mBase, ...)

stevel05

Expert
Licensed User
Longtime User
In a custom view (and generally), it is easier to create a layout to load other CustomViews, and load that. Seems overkill if you only want one view, but the bonus is that it manages resizing (providing you put anchors in the layout). Resizing may not (yet) be an major issue for Android especially using B4XPages, but it's a good idea as a basic principle.
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
If, however, you want to create some Views in the project from code, you should know that you can do this with "native" Views, such as Button, Label, EditText, etc., but you can't do it with Custom Views; you'll always have to insert them into a Layout.

https://www.b4x.com/android/forum/t...ew-here-s-how-to-add-programmatically.118037/

For B4XImageView there is an exception: you can use XUIViewsUtils.CreateB4XImageView
B4X:
Dim imgSwitch As B4XImageView
imgSwitch = XUIViewsUtils.CreateB4XImageView
mBase.AddView(imgSwitch.mBase, ...)
 
Upvote 1
Solution
Top