Android Question get B4XPage from a XUI CustomView

Alessandro71

Well-Known Member
Licensed User
Longtime User
How can I can get the B4XPage object which a CustomView belongs to, from inside a CustomView sub.
Maybe from mBase itself?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to get B4XPageInfo from a view. You do need to pass mBase for custom views, as this is the real view.

B4X:
Public Sub GetPageInfoFromView(view As B4XView) As B4XPageInfo
    Dim pi As B4XPageInfo = Null
    Do While view.IsInitialized And pi = Null
        pi = B4XPages.GetManager.GetPageInfoFromRoot(view)
        view = view.Parent
    Loop
    Return pi
End Sub
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
You can use this code to get B4XPageInfo from a view. You do need to pass mBase for custom views, as this is the real view.
But then what can you do with it?

1609055608342.png


You can only get a generic object, without having access to its properties and methods.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
this was actually for the Initialize of the Camera object for B4i in a cross-platform project
B4X:
    Dim p As B4XPageInfo = B4XUtils.GetPageInfoFromView(mBase)
    Private Camera As Camera
    Camera.Initialize("Camera", B4XPages.GetNativeParent(p.B4XPage))
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
B4X:
Public Sub GetPageInfoFromView(view As B4XView) As B4XPageInfo
    Do While True
        Dim pi As B4XPageInfo = B4XPages.GetManager.GetPageInfoFromRoot(view)
        If pi <> Null Then
            Return pi
        Else
            view = view.Parent
        End If
    Loop
    Return Null
End Sub

the above code, which I put in a code module, while no errors are displayed in the IDE, produces the following message in the compilation phase:

Compiling generated Java code. Error
B4A line: 123
view = view.Parent
src\com\project\check\pro\test\b4xutils.java:69: error: unreachable statement
;
^
 
Upvote 0
Top