Android Question button_click events don't seem fire when using b4xdrawers over b4xpages when the drawer related codes are packed in a customed class

Hi,
I implemented a custom class that creates and initializes a b4xdrawer for each page. (after reading this thread)
The left panels of the drawers use LayoutA, while the center panels use LayoutB and LayoutC with several buttons in each layout.
Although all buttons can be seen on the screen, the button_click events don't seem to work(no responses at all)
I guess there must be something that I did wrongly. Just don't know what it is and how to get it right.

What I've tried:
  1. disable the customer class and do the initialization of a drawer in the page module, then it will work properly.
  2. disable the customer class and move drawer-related code into a custom sub of the page module, then it will work properly.
  3. tried to use breakpoints, the phenomenon was that the code flow didn't go to sub button4_click

The code is like this:

B4X:
****xDrawerSimpler_Cls****
'a customed class
Sub Class_Globals
    
    Private mDrawer As B4XDrawer
    Private mCallback As Object
    Private mUniWidth As Int=100dip' widths of all leftPanels
    Private mLayoutName_Left="LeftPanelLayout" As String 'Layout name of left panels
    
End Sub

Public Sub Initialize(Callback As Object,parent As B4XView,CenterLayout As String)

    mCallback=Callback
    mDrawer.Initialize(mCallback,"Drawer",parent,mUniWidth)
    mDrawer.CenterPanel.LoadLayout(CenterLayout)
    mDrawer.LeftPanel.LoadLayout(mLayoutName_Left)

End Sub

public Sub getActualDrawer As B4XDrawer
    Return mDrawer
End Sub


****B4XMainPage*****

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private drawer1 As xDrawerSimpler_Cls
    Private Button4 As B4XView
    Private p2 As Page2
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    p2.initialize
    drawer1.Initialize(Me,Root,"MainPage")
    B4XPages.AddPage("p2",p2)
End Sub

Private Sub Button4_Click  'This event doesn't fire.
    B4XPages.ShowPage("p2")
End Sub
The codes are:
 
What do you see in the UI? Does the button show that it is being clicked?
Once the software starts, I see some buttons whose numbers and positions are just as I expected. If I swipe from the left side of the screen to the right, the left panel of the b4xdrawer appears. When I click button 4, a shadow quickly flashes across the button. So yes, I think the button shows that it is being clicked.
 

Attachments

  • XRecorder_Edited_31072024_154927.gif
    XRecorder_Edited_31072024_154927.gif
    222.7 KB · Views: 59
Upvote 0
The button is indeed clicked.

The button event will be raised in the module that loaded the layout. If I understand your code then the button event will be raised in xDrawerSimpler_Cls.
As you analyzed, once I placed the event response code into the class code, the button event indeed started working properly.
However, in my project, because the layout of each center panel of the b4xdrawer will be different, the class module cannot know in advance which layout file needs to be loaded. Moreover, if I implement the views-related code into the class module, I won't be able to use these views in the b4xpage module. Using a class module to simplify drawer-related code seems to cause more trouble. Is there any solution for this?
 
Upvote 0
Top