Android Question One single Drawer in multi Page Project?

Guenter Becker

Active Member
Licensed User
Hello,
Using the B4XDrawer with B4XPage raises a question I like to ask. If we need only one Drawer as a central main Menu I do not like to implement the drawer subs/code in each B4XPage again and again. In a B4XPage Project the Idea is to implement the drawer not on each Page but one level higher on Activity level (Main). Ist that possible? Is there are better way? How?

Thank you for the answer.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You have two options:

1. Implement it in the main activity. This will only work in B4A.
2. Implement it in a class and create a class instance on each of the pages. Example here: https://www.b4x.com/android/forum/threads/138771/#content
The second option will require some additional work to make it cross platform but it should be possible to do.
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Ok thank you. To implement it in the main is what I prefer. I tried it but run into problem.

Activity create:
    Drawer.Initialize(Me,"Drawer",Me,400dip) ' this wrong and raises an error
    'Drawer.CenterPanel.LoadLayout("MainPage")
    Drawer.LeftPanel.LoadLayout("MainMenu")

To initialize the drawer I understand to set the callback to Me but what is the correct reference to set for the 2nd it's a b4xview I do'nt have it in Main.
The next is what to load? LeftPanel is the Drawer OK, but the central panel? SHould it be the B4XMainPage?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
this wrong and raises an error
Hiding the full error is a good way not to get help.
Try to reproduce it in a small project and upload the project.
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Sorry, I know that this is wrong! It was only an example. If you let it run you get the error dat the 2nd Me is not accepted because the Me is pointing to an activity and not to an B4XView.
 
Upvote 0

Guenter Becker

Active Member
Licensed User
ok, thank you. One thing left, how to open the drawer from a button on the b4xpage?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
how to open the drawer from a button on the b4xpage?
B4X:
' Two subs in the drawer
Public Sub getLeftOpen As Boolean
    Return IsOpen
End Sub

Public Sub setLeftOpen (b As Boolean)
    If b = IsOpen Then Return
    Dim x As Float
    If b Then x = 0 Else x = -mSideWidth
    ChangeOffset(x, False, False)
End Sub
 
Upvote 0
Top