Android Question How to add, show/hide 2 or more panels inside one b4xpage class ?

carlbertech

Member
Iam trying to show/hide 2 layouts in one b4xpage class
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Dim Panel1, Panel2 As B4XView ' I add two panels
....
Sub B4XPage_Created (Root1 As B4XView)
Panel1.Initialize("") : Panel2.Initialize("")
Panel1.LoadLayout("Layout1") : Panel2.LoadLayout("Layout2")

Root=Root1
' Activity.AddView(Panel2, 0, 0, 100%x, 100%y) ' This does not work because is B4XPage not B4A Activity

Root.LoadLayout("Page1") ' Instead LoadLayout Page I would like show Panel1
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
hi,
You are nearly there.
All you need to do is have a master panel which is loaded into Root. This contains the 2 other panels, panel1 & panel2, each of which is the full size.
Then load the layouts into Panel1 and Panel2.
Then show/hide the 2 panels as required.

so
B4X:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Dim Panel1, Panel2 As B4XView ' I add two panels
....
Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("Page1") ' Page1 contains panel 1 & panel 2
'Panel1.Initialize("") : Panel2.Initialize("") ' No need for this line
Panel1.LoadLayout("Layout1") : Panel2.LoadLayout("Layout2")

flippanels(true) ' show panel1

' Activity.AddView(Panel2, 0, 0, 100%x, 100%y) 'No need for this line

....

private sub flippanels(show1 as boolean) ' for use later in the code
panel1.visible = show1
panel2.visible = not(show1)

end sub
 
Upvote 0

carlbertech

Member
Thansk for your support!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…