B4J Question How to know if a menubar exists(?)

Cableguy

Expert
Licensed User
Longtime User
Hi guys

While creating a lib, I am facing an uncommon issue... My lib will add a button to the MainForm.RootPane but the X position will depend of the presence or not of a menubar. How can I chech if an object (node) of the menubar type exists?
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

something like

B4X:
For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
  If n Is MenuBar Then
    Log("MenuBar found")
  End If
Next
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Thanks Rob, exactly what I was looking for... I also was successful by converting the object to a string and check the first 7 characters... kinda of made it more complex than needed although it worked.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Another solution is to use the View Tag Property (assign unique value or string) to search in case if of multiple same type of views, like

B4X:
    For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
        If n.Tag <> Null And n.Tag = "MenuBarA" Then
            Log("MenuBarA found")
        End If
    Next
Note: Changed first code snippet by adding if n.Tag <> Null according hint in post #5

Or

B4X:
For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
        Dim s As String = n.Tag
        If s.EqualsIgnoreCase("MenuBarB") Then
            Log("MenuBarB found")
        End If
    Next
 
Last edited:
Upvote 0
Top