B4J Question How to add a new form (Newbie)

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

I am using the Open Designer...

How to add a new form to a project (B4A under Project Add New Module >Acitivity)?
How to start or load the new form from Main?
Are there examples of multiform projects?

I have searched, but I do not seem to get the answer - I saw a modal form example using a Class module...

For example, simple Financial app with a Main Form, Customer Form, Transaction Form, Reporting Form....

Thank you.

Sandy (Newbie B4J)
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
Just create a new Form variable, initialize it, load a layout and then show it:
B4X:
Dim newForm As Form
newForm.Initialize("newForm", 100,100)
newForm.RootPane.LoadLayout("newFormLayout")
newForm.Show
If you take a look at the template code in a UI app, all those steps are performed with MainForm, with the exception of initialization, in Process_Globals() and AppStart().

You can create the newFormLayout with the Designer. The above code can appear in your Main module; no need to create a new module for it as in B4A and Activities. You can, if you want, make a Form a member of a class (click Project>Add New Module>Class Module), but that isn't necessary. I would recommend putting newForm's event subs and MainForm's event subs in separate regions for purposes of code readability:

B4X:
#Region MainFormEvents
'MainForm events
#End Region

#Region newFormEvents
'newForm events
#End Region
but again, it's not necessary.
 
Upvote 0
Top