Android Question B4XDrawer - how to make available for each page

LucaMs

Expert
Licensed User
Longtime User
1607472107747.png


First look; it is declared and used in the B4XPage2 page, so the first thing that comes to mind is to duplicate the code in the other pages.

It is not unlikely, however, that we can do better. I could think of B4XMainPage, but it is not always visible; so maybe not, maybe you need to do as said above.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I should study the source of B4XDrawer (but I think that the author of it knows it well :)); perhaps it is possible to initialize it in the B4XMainPage and add a Parent property to the source, to which you can pass the Root of the current foreground page from time to time.

But for now I give up, I go back to my problems :(
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
I've looked at the BX4_Pleroma example, but I am of the opinion that its too soon for a mind that is just grappling to understand the concepts of B4XPages yesterday, its just too soon, there is just a lot happening with that project, there is code there for a class called DrawerManager perhaps it does that.

1607473657554.png


#Explain.It.Like.Im.5
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
How would I make the Drawer available for every page that is shown/navigated to?
And for example with web frameworks, one is able to show the drawer on medium and large devices and hide it on small devices. I guess with that thought one should be able to detect a device size, so that for example if you run on B4J the same project, it shows and when the screen is resized it hides. #NewbieThoughts
 
Upvote 0

udg

Expert
Licensed User
Longtime User
You could start with @agraham 's example here.
Then modify it according to the excellent Erel's suggestion (a class that defines what's available as part of the left menu)
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Nothing special is needed. You can add a drawer instance to each of the pages.
You can implement the code that builds the drawer in its own class and create a new class instance in each of the pages.

Do you mean the code won't have to be duplicated in each code reference to the B4XDrawer?
That's the main hope that code doesn't get duplicated, and I think your idea for a class, right?
-Mark
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
And the next trick would be to have a Drawer-selected-item open/navigate to a page and still keep the same Drawer available.
Something like Outloook for Android, which I use every day for work - I like its simplicity. The same menu options are available for all pages and selecting a drawer item navigates to the specific selected page.

I looked at @agraham 's example and it sure is getting a lot complicated with JavaObject references. That makes it a little complicated, especially if you have no idea what java code/property to use.
I was hoping for something a little along the road of being RAD in it's approach to coding and object references.
Who said programming was easy? Oh, that's right Bill Gates - it's just logic.

Erel - can you build an example relating to this topic and with the class with which you have mentioned?

Much appreciated,
Mark Stuart
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Thank you @klaus . I'm reading it and I see the B4XPages.Show may be an approach when selecting a Drawer item.
Would that be the case for navigating to pages?
I'm new to the Pages and Drawer objects, so now is the time to learn from the booklets.

Thanx,
Mark Stuart
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Do you mean the code won't have to be duplicated in each code reference to the B4XDrawer?
You will never see an answer from me that includes duplicating code. Implement the drawer in a class and create an instance in each of the pages. Nothing special.
No need for any JavaObject.

Try it and you will see that it is simple.
 
Upvote 0

kisoft

Well-Known Member
Licensed User
Longtime User
You will never see an answer from me that includes duplicating code.
It is possible but in this thread...
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Looking at the B4XPages - B4XDrawer example, I see that the Drawer is made available for Page2 only.
How would I make the Drawer available for every page that is shown/navigated to?

Thanx,
Mark Stuart

Hello,
I am just devloping a B4XPages App with many Pages and each of them uses the drawer to show a main menu. The solution I took is very easy:
  1. In each page declare the drawer as private global instance (Private Drawer as B4XDrawer).
  2. Create a Modul and in the module some subs to handle the drawer management. For example: a) sub to build a tree menu, b) sub to react on tree menu click,.
  3. In the Page Creation Event of the B4XMainPage call the modul sub who creats the menu tree items and transfer and hold the build/item Parameter with a public map.
  4. In the Page Creation Sub of each Page using the drawer call the modul sub to insert the tree menu into the drawer instance of the page.
  5. Open the Page Drawer by a Button of the page and close the drawer as part of the modul menu item click event.
stay well
 
Upvote 0
Top