D Duck Member Mar 9, 2023 #1 Hi, I like to create a bunch of buttons at runtime on the B4XMainPage as I understood B4Xpages is recommended. I can declare and index them by the tag property: <Code> Private Btn(20) as Button For i = 1 to 20 Btn(i).Initialize("Btn") Btn(i).tag = i Next </Code> But how do I make them visible? Activity.AddView is not available on the B4XMainPage. If I move all to the Main page and declare the buttons as Public they are not available on the B4XMainPage. I appreciate your help.
Hi, I like to create a bunch of buttons at runtime on the B4XMainPage as I understood B4Xpages is recommended. I can declare and index them by the tag property: <Code> Private Btn(20) as Button For i = 1 to 20 Btn(i).Initialize("Btn") Btn(i).tag = i Next </Code> But how do I make them visible? Activity.AddView is not available on the B4XMainPage. If I move all to the Main page and declare the buttons as Public they are not available on the B4XMainPage. I appreciate your help.
Erel B4X founder Staff member Licensed User Longtime User Mar 10, 2023 #2 1. Don't use arrays. Use a List. 2. The indexes are wrong. They go from 0 to 19. See point #1 for a better solution. 3. Code: For i = 1 To 20 Dim btn As Button btn.Initialize(...) Buttons.Add(btn) Root.AddView(btn, ...) Upvote 0
1. Don't use arrays. Use a List. 2. The indexes are wrong. They go from 0 to 19. See point #1 for a better solution. 3. Code: For i = 1 To 20 Dim btn As Button btn.Initialize(...) Buttons.Add(btn) Root.AddView(btn, ...)