Hello!
I would like to ask if it's possible to view the same Google Map to two pages!
I mean I want to initialize one map instance, show it for example to the MainPage and when I show another page, the same map is appeared without reinitialisation needed!
Thank you in advance!
Hello Luca!
Thank you for your response!
I have read the B4XPages benefits!
I'm talking about mapFragment view and I can't figure out how to move it to another Page! ?
Indeed; I've never used mapFragment, which requires various things in the manifest, I think (and I'm starting to use B4XPages right now) and tried to move a WebView.
In the B4XMainPage I have:
B4X:
Sub btnPage2_Click
Dim P2 As Page2
P2.Initialize
B4XPages.AddPageAndCreate("Page2", P2)
WebView1.RemoveViewFromParent
P2.PassView(WebView1)
B4XPages.ShowPage("Page2")
End Sub
B4X:
' Page2
Public Sub PassView(Vw As B4XView)
Root.AddView(Vw, Vw.Left, Vw.Top, Vw.Width, Vw.Height)
End Sub
and it works (I don't know if there is a better way to do it).
1 - declare P2 in the Class_Globals of B4XMainPage, initialize and add it to B4XPages in B4XPage_Created instead of inside the btnPage2_Click event routine (if you press it more then once the app doesn't crash, you just get a log with a warning that the page is already added to B4XPages but doing so it is more correct);
2 - I was going to write that it would have been better to put the view addition in a Try-Catch block to avoid adding the same View multiple times to Page2 but... then I tried and no exception is raised in case the View exists already (in this case the log shows always 2)! Great!
B4X:
Public Sub PassView(Vw As B4XView)
' Try
Root.AddView(Vw, Vw.Left, Vw.Top, Vw.Width, Vw.Height)
' Catch
' Log(LastException)
' End Try 'ignore
Log(Root.NumberOfViews)
End Sub