Android Code Snippet Using B4XPage and more ...

This is a try, to collect the (to me) most important samples of B4X code here. I love to develop with B4X, but I often have bigger breaks in between and really then plenty of time to go back to the basics. I hope it is also helpful to others. I need solutions that works for B4A and B4i, so B4XPages are ideal to me. Everything that is special in B4i I will describe in the iOS code snippets.

In Menu "Project / Add New Module / Class Module / B4XPage" choose a name like "FrmPage1" (choose "Add module to parent folder", as it is the same file for B4i)
In Menu "Designer / Open Designer" save the design for the new form with a name like "viewFrmPage1"
Of course you can choose every name, but with this system you always know, what layout is for what page and you see all layouts together in the files manager.

Define and add the new page in B4XMainPage:
Sub Class_Globals
    Main.cG.Initialize 'object of "GlobalClass" for easy (global) access from every page (in Main/Process_Globals: Public cG As GlobalClass)

    Root = Root1
    Root.LoadLayout("viewFrmPage1")
    B4XPages.SetTitle(Me, "My Page1")
 
    'declare other B4X-Pages here
    Public pgPage1 As FrmPage1
    'other pages ...

End Sub

Private Sub B4XPage_Created (Root1 As B4XView)

    'add other B4X-Pages here
    pgPage1.Initialize
    B4XPages.AddPage("pgPage1", pgPage1)
     'other pages ...

End Sub


'Navigate to page:
B4XPages.ShowPage("pgPage1")

I use my global Class ("cG" from "xGlobalClass") for all code and data that I want to access from every page.

Using SQLite

Load a List from SQLite and show it in xCustomListView

Resumable Subs and some basic dialogs

Multi selection list with B4XPreferencesDialog

Prevent the display from turning off
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…