Android Question B4XPages with TabStripViewPager + separate code module for each page

Ralle80

Member
Hi,

I am facing the same problem but struggling with the solution of the following thread:


The problematic line is:

B4X:
tab1.Initialize(PanelFromLayout)

Do I have to replace "PanelFromLayout" with the real panel name, which is generated from designer ?
I tried to do so, but then it will show error "Array expected." which confuses me - when generating the new class module, there is no parameter for the Initialize method at all...

I then removed the parameter completely and just called tab1.Initialize. This lets the code compile successfully and the Tab UI looks like it should be, but when I e.g. place a button in my layout (using Designer) and then "Generate Click" event, this Click event is always placed in "Target": B4XMainPage.

Because I want the code to be separated for each Tab Page, I moved the Button declaration and Click Event into the corresponding class module, but then the Click event is never executed when I tap the button...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Do I have to replace "PanelFromLayout" with the real panel name, which is generated from designer ?
You need to create a layout with a single panel, which is anchored to all sides. This is the PanelFromLayout.

The "tab class" is not a B4XPages class. It is a class with an Initialize sub that looks like this:
B4X:
Public Sub Initialize(Root As B4XView)

This will actually be the "PanelFromLayout" panel.
 
Upvote 0

Ralle80

Member
Hi Erel,

thanks for your reply - but adding the (Root As B4XView) parameter and calling it with the corresponding panel did not make any difference - the button event is not triggered.

Here's my code:

B4XMainPage:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private TabStrip1 As TabStrip
    Private pnlDoors As B4XView
    Private pnlPower As B4XView
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    
    TabStrip1.LoadLayout("power", "Strom")
    Dim pwr As clsPower
    pwr.Initialize(pnlPower)
    
    TabStrip1.LoadLayout("doors", "Türen")
    Dim doors As clsDoors
    doors.Initialize(pnlDoors)
    
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Class clsPower:
Sub Class_Globals
    Private pnlPower As B4XView
    Private Button1 As B4XView
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Root As B4XView)
    
End Sub


Private Sub Button1_Click
    MsgboxAsync("CLICK","Test")
    Log("PWR BUTTON CLICKED!")
End Sub

Designer.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Create a layout with a single panel, anchored to all sides. For simplicity name this panel PanelFromLayout and name this layout TabPanel.
2. The code should look like this:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private TabStrip1 As TabStrip
    Private PanelFromLayout As B4XView
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    TabStrip1.LoadLayout("TabPanel", "Strom")
    Dim pwr As clsPower
    pwr.Initialize(PanelFromLayout)
    
    TabStrip1.LoadLayout("TabPanel", "Türen")
    Dim doors As clsDoors
    doors.Initialize(PanelFromLayout)
End Sub

3. Load each tab layout in its own class:
B4X:
Public Sub Initialize(Root As B4XView)
    Root.LoadLayout("doors")
End Sub
 
Upvote 0
Top