How to manage code & GUI?

dkjorgi

New Member
Licensed User
Longtime User
I am new to Basic4Android and would appriciate if someone could explain or point me to a good example of how you organise an application which will have 10 different screens/forms while at the same keeping the code manageable and not in one big lump.

I see some examples where people have used panels to load screens into these and then hide and unhide these panels. The disadvantage here seems to be that ALL the code will exist within one activity.

That leads me to think about having an activity for each form (screen) I do. The advantage here is to have the code in manageable chunks. Are there any disadvantages?

How will I load a new activity from within an existing activity and how will I unload one and return to the previous?

I am sorry if these are basic questions and would appreciate any pointers anyone can give.
 

Cableguy

Expert
Licensed User
Longtime User
You do not need to use Panel to show/hide a Form or "screen"...You can use a Layout for it, and then load it as needed..
The new Beta (1.2) allows for static code, that is to say, you can now call a sub in a diferent "module", keeping this way the code flux as simple as you want or need..
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
I am using the panel switch method mainly because its faster (and easier to handle) than jumping in and out of other activities

In essence I use a function such as ShowPanelNumber(p) which hides all panels and shows the indicated panel 'p'

Talking of layouts, my first thoughts were to switch between them by loading each as required but I found that previous layouts still remain on screen.
I was hoping that calling Activity.Initialise("") would remove any existing layouts but it doesn't

Erel,
Do you have a suggestion on how to easily remove all currently loaded views in an activity? In the example below both layouts remain on screen

B4X:
' 2 Layouts - switch

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime=True Then
      Activity.Initialize("")
      Activity.LoadLayout("layout1")
   End If
End Sub

' ButtonL1 is a button created in layout1
Sub ButtonL1_Click
   Activity.Initialize("")
   Activity.LoadLayout("layout2")
End Sub

' ButtonL2 is a button created in layout2
Sub ButtonL2_Click
   Activity.Initialize("")
   Activity.LoadLayout("layout1")
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Erel,
Do you have a suggestion on how to easily remove all currently loaded views in an activity? In the example below both layouts remain on screen
Instead of loading the layout to the activity, load it to a panel (with Panel.LoadLayout) and then add this panel to the activity.
To switch to a new layout you can call Panel.RemoveView or change the panel visibility and add a new panel with the new layout.
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
Erel, a little off topic, but exactly what happens when an Activity.Initialize method is executed?
 
Last edited:
Upvote 0
Top