Marcos Alves Well-Known Member Licensed User Longtime User Nov 12, 2019 #1 Hello all, I trying to create a B4XSwitch in runtime using the code: Code: Copy Dim itemEnabled As B4XSwitch itemEnabled.Initialize(Me,"itemEnabled") itemEnabled.mBase.AddView(pnlEditItem,10,panelPos,txtPrice.Height * 4,txtPrice.Height) But this is generating the error: java.lang.RuntimeException: Object should first be initialized (B4XView). When I add the b4xswitch using the designer there is no error. What am I doing wrong? Is it impossible to add B4Xviews at runtime ?
Hello all, I trying to create a B4XSwitch in runtime using the code: Code: Copy Dim itemEnabled As B4XSwitch itemEnabled.Initialize(Me,"itemEnabled") itemEnabled.mBase.AddView(pnlEditItem,10,panelPos,txtPrice.Height * 4,txtPrice.Height) But this is generating the error: java.lang.RuntimeException: Object should first be initialized (B4XView). When I add the b4xswitch using the designer there is no error. What am I doing wrong? Is it impossible to add B4Xviews at runtime ?
LucaMs Expert Licensed User Longtime User Nov 13, 2019 #2 https://www.b4x.com/android/forum/t...m-views-and-dialogs.100836/page-2#post-634602 Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Nov 13, 2019 #3 Marcos Alves said: Is it impossible to add B4Xviews at runtime ? Click to expand... You are confusing different things. B4XSwitch is not a B4XView. B4XSwitch is a custom view. The correct question is whether it is possible to add custom views at runtime. The answer is that you can create a layout file with the custom view and load it whenever you want to add one. You can use the same layout file to create any number of views. Upvote 0
Marcos Alves said: Is it impossible to add B4Xviews at runtime ? Click to expand... You are confusing different things. B4XSwitch is not a B4XView. B4XSwitch is a custom view. The correct question is whether it is possible to add custom views at runtime. The answer is that you can create a layout file with the custom view and load it whenever you want to add one. You can use the same layout file to create any number of views.
Marcos Alves Well-Known Member Licensed User Longtime User Nov 13, 2019 #4 Erel said: The answer is that you can create a layout Click to expand... And maybe the direct answer is "no, you MUST to create a layout with the custom view before." - but why? Why can't I use a custom view like I use a traditional view, defining it in command line? Erel said: create a layout file with the custom view and load it whenever you want to add one Click to expand... thanks @Erel . I'll use this technique . Upvote 0
Erel said: The answer is that you can create a layout Click to expand... And maybe the direct answer is "no, you MUST to create a layout with the custom view before." - but why? Why can't I use a custom view like I use a traditional view, defining it in command line? Erel said: create a layout file with the custom view and load it whenever you want to add one Click to expand... thanks @Erel . I'll use this technique .
Erel B4X founder Staff member Licensed User Longtime User Nov 13, 2019 #5 Marcos Alves said: And maybe the direct answer is "no, you MUST to create a layout with the custom view before." Click to expand... Not exactly true. You can dynamically create custom views using a layout file. Why? Because it makes it easier for developers to build custom views and it is very simple for other developers to use those custom views. Upvote 0
Marcos Alves said: And maybe the direct answer is "no, you MUST to create a layout with the custom view before." Click to expand... Not exactly true. You can dynamically create custom views using a layout file. Why? Because it makes it easier for developers to build custom views and it is very simple for other developers to use those custom views.