Android Question Creating Multiple Panels Programmatically

epsharp

Member
Licensed User
Longtime User
I am converting a B4PPC module to B4A. I use a single "Form" and many, many Panels all of which are created in the "App_Start" Routine. What the user looks at depends on button clicks and the view is controled by:

B4X:
Panel1.Bringtofront
Panel1.Visible = True
.
.
Panel2.BringtoFront
Panel2.Visible = True
Panel1.Visible = False

Although I have been using B4PPC for 10 years, this is my first foray into B4A. Considering the Android "life_cycle" I believe it would be much more efficient to break the massive "form build" cycle into individual routines (Panel with buttons, Panel with text input, etc). Where I would make the panel visible, instead create the Panel at that point and place it on the view. Where I would make it invisible, simply remove it.

B4X:
Create_Panel("pnFront")
.
.
pnFront.Remove
Create_Pane("pnBack")

Then it would not matter about initialization because all "Forms/Views" are created on demand. I should also point out that on any given day, the majority of panels would never be looked at. Is this approach better than creating all panels at app start or is their some price-to-pay in Android for re-creating views.

Thank you for your assistance.

Regards

Ed Sharp
 

udg

Expert
Licensed User
Longtime User
You can go with the on-the-fly creation of Panels.
You can even consider to prepare a few layouts for those panels that should coexist and LoadLayout them.
Another good option could be the expandable CLV (look for xCustomListView) where you add your panel to a scrooling view capable of expand each panel at will.
I'd say that the final choice will depend on your real needs.
 
Upvote 0

epsharp

Member
Licensed User
Longtime User
Thank you for your reply. I wrote a program to read an existing B4PPC source file and convert the B4P IDE generated code into B4A, which worked fine. When I tried to test it, the compiler crashed. I have attached the program and the error. I obviously need to use individual routines instead of inline code but I can`t find a solution. In B4PPC, I used the following in every program, simply changing the Menu Array:

B4X:
    tp  = 130 
    mx = ArrayLen(menu()) - 1
   
    For i = 0 To mx
        bttx = menu(i) 
        btln = SR.Len(bttx) * 14
        btlf = Int((fwid - btln) / 2)
        bt   = "bPS1AM" & i+1
   
        AddButton("fMUPS1AM",bt,btlf,tp,btln,fbut,SR.Strip(bttx) & " ")
        AddEvent(bt,Click,"Button_Handler")
        Control(bt,Button).FontColor = cWhite
        Control(bt,Button).FontSize  = 14
        If i = mx Then Control(bt,Button).Color = cRed Else Control(bt,Button).Color = cBlue
        tp = tp + fbut + fgap
    Next

Use of the "Control" function allowed you to use strings for view objects, but I can find no equivalent in B4A.

I have looked at the TicTacToe example but the buttons have no names. Think of modifying the program for the computer to play against you. How would the computer put an X in the center button? I need to be able to hide/show buttons and/or change the Text depending on the status of my program.

Any further assistance would be greatly appreciated
.
 

Attachments

  • FormTest.zip
    13.1 KB · Views: 172
  • B4aError.jpg
    B4aError.jpg
    27.6 KB · Views: 190
Upvote 0
Top