Cursussen/Courses Codesnippets     Top 
B4A-lists - B4XMainPage


1. Add pages
In the IDE window we need to add the pages we just designed and make a menu to access the category or subcategory page.
Activate the B4XMainPage tab by clicking on it.
To add pages you click on the menu Project / Add New Module / Class Module / B4Xpage and give it a good name. Make sure you add the module to the parent folder.
You now have 2 more tabs.


2. Declarations
Declare the private variables for the pages in the Sub Class_Globals.
Private catpage As CategoryPage
Private subcatpage As SubcategoryPage


3. Initializations
Initialize the pages, add them to the B4Xpages collection and use the subroutine “menuitem_add” to add the menuitems to the menubar. This code is added to the subroutine: B4XPage_Created.
catpage.Initialize
subcatpage.Initialize
B4XPages.AddPage("Category",catpage)
B4XPages.AddPage("Subcategory",subcatpage)
' add pages to the menubar
menuitem_add(Me, "Category")
menuitem_add(Me, "Subcategory")


4. Menuitems
Write the menuitem_add subroutine: Provide an event handler for the menu click:
Private Sub menuitem_add(objpage As Object, itemname As String)
	Private mnuitem As B4AMenuItem = B4XPages.AddMenuItem(objpage,itemname)
	mnuitem.AddToBar = True
End Sub

Sub B4XPage_MenuClick (Tag As String)
	B4XPages.ShowPage(Tag)
End Sub


5. Second run
The app now looks like this: