B4J Question How can B4xViews + Drawer be used to change pages?

Credo

Member
I may have worded it wrong, but In the forum below I tried studying the template to copy the effect of changing the pages using Custom views and Drawer I think.
I dont fully understand how they did it, but I want to use this effect for my project.
Can someone point me to a thread or tell me how they did it?

https://www.b4x.com/android/forum/threads/project-template-b4j-dashboard-drawer.161142/#content

Literally been at it for days, Literally feel like I'm chasing a ghost lol HAHAHA.
 

aeric

Expert
Licensed User
Longtime User
I try to understand your question.
I am not sure you are confused with the show new page or the show/hide menu panels.
I assume the former.

First of all, this template is a little bit different from the ordinary B4XPages template.
It is based on this example by Erel.
B4XPages maybe more simpler.

Instead of adding new B4XPage, this template uses standard class with a Show method set as Public.
B4X:
Public Sub Show (Parent As B4XView)

When the caller form (B4XMainPage or Form) opens a new page from a user click action on a menu, we first check PnlCenter (panel used for displaying the layout) is empty or already loaded with another layout.
B4X:
Private Sub ClvMenuMini_ItemClick (Index As Int, Value As Object)
    If ContentEmpty = False Then PnlCenter.GetView(0).RemoveViewFromParent
    CallSub2(Value, "Show", PnlCenter)
End Sub

The ContentEmpty sub checks for any views are added to the PnlCenter.
B4X:
Private Sub ContentEmpty As Boolean
    Return PnlCenter.NumberOfViews = 0
End Sub

If it is not empty, we need to remove the existing "layout" so we can load a new layout to the same "container" again.
B4X:
PnlCenter.GetView(0).RemoveViewFromParent

Then we use CallSub2 to call the Show sub in class Form1 by passing the parameter PnlCenter as the Parent view.
B4X:
CallSub2(Value, "Show", PnlCenter)

You can see in Form 1, the Show sub is:
B4X:
Public Sub Show (Parent As B4XView)

The Component value passed to CallSub2 is an Object type Form1 that we added when we create the items for CustomListView (ClvMenuMini).
B4X:
Dim frm1 As Form1
frm1.Initialize
B4X:
ClvMenuMini.Add(CreateMiniItem(Chr(0xF004), ClvMenuMini.AsView.Width), frm1)

That's it.
I hope I have explained well.

If I answered your question, please mark the checkmark at the right side as Solution.
 
Last edited:
Upvote 0

Credo

Member
I try to understand your question.
I am not sure you are confused with the show new page or the show/hide menu panels.
I assume the former.

First of all, this template is a little bit different from the ordinary B4XPages template.
It is based on this example by Erel.
B4XPages maybe more simpler.

Instead of adding new B4XPage, this template uses standard class with a Show method set as Public.
B4X:
Public Sub Show (Parent As B4XView)

When the caller form (B4XMainPage or Form) opens a new page from a user click action on a menu, we first check PnlCenter (panel used for displaying the layout) is empty or already loaded with another layout.
B4X:
Private Sub ClvMenuMini_ItemClick (Index As Int, Value As Object)
    If ContentEmpty = False Then PnlCenter.GetView(0).RemoveViewFromParent
    CallSub2(Value, "Show", PnlCenter)
End Sub

The ContentEmpty sub checks for any views are added to the PnlCenter.
B4X:
Private Sub ContentEmpty As Boolean
    Return PnlCenter.NumberOfViews = 0
End Sub

If it is not empty, we need to remove the existing "layout" so we can load a new layout to the same "container" again.
B4X:
PnlCenter.GetView(0).RemoveViewFromParent

Then we use CallSub2 to call the Show sub in class Form1 by passing the parameter PnlCenter as the Parent view.
B4X:
CallSub2(Value, "Show", PnlCenter)

You can see in Form 1, the Show sub is:
B4X:
Public Sub Show (Parent As B4XView)

The Component value passed to CallSub2 is an Object type Form1 that we added when we create the items for CustomListView (ClvMenuMini).
B4X:
Dim frm1 As Form1
frm1.Initialize
B4X:
ClvMenuMini.Add(CreateMiniItem(Chr(0xF004), ClvMenuMini.AsView.Width), frm1)

That's it.
I hope I have explained well.
Hi Aeric!

I really appreciate the response, I think I understood the method you and Erel used to make this effect.
Although I will have to apologize for being vague on this post. English is not my first language.

The effect I am trying to create on my project is loading a layout on initial Load.

The theory I tried to do was to add the contents of the onclick function into InitPanel, but thisof course did nothing.
B4X:
    Dim frm1 As Form1
    If ContentEmpty = False Then PnlCenter.GetView(0).RemoveViewFromParent
    CallSub2(frm1, "Show", PnlCenter)

I wanted to ask for help on how I could achieve this.
But if it is not possible then I fully understand and will just work around it.



Again I really appreciate this,
Thank you so much!
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
The effect I am trying to create on my project is loading a layout on initial Load.
I have missed to release version 0.003.
I think the latest version has what you are looking for.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
In version 0.003, the template just load the layout. It doesn't actually load the page or called Show sub. If user clicks the menu to open the same initial page again, it will reload the page with a new layout and state. If the layout contains text fields, the values will be cleared.

I have fixed this in version 0.004.

If I answered your question, please tick the checkmark at the right side as Solution.
 
Upvote 0
Top