Android Question MenuOnAnyView

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All,
I have a menu thar acts as an SQL Filter, to act in table sitting below.
The Menu is invoked from a label that Reads "Type of Object" and when clicked opens the menu with a pre filled list of options.
However, the button is on the top of the form and the Menu opens Upwards, not showing some of the items.
Is it possible to force the menu to open downwards ?

Thanks
 

JohnC

Expert
Licensed User
Longtime User
It seems like the menu object it somehow tied to a "parent" view on the form and it is designed to open near it's "parent" view.

Please provide the code to create the menu object and the code to display the menu.
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hi, that is so. the menu is tied to the label that opens the menu itself, i said button, but is a label

the click code that triggers the open

B4X:
Sub labelTypeObjectFilter_Click
   
    If ObjectTypePopMenu.MenuIsOpen Then
        ObjectTypePopMenu.CloseMenu
    Else
        ObjectTypePopMenu.OpenMenu
    End If

End Sub

and the Initialization of the menu in the Activity_create sub

B4X:
ObjectTypePopMenu.Initialize(Activity, Me, labelTypeObjectFilter, Consts.ColorMain, Colors.White, Consts.ColorSub, True, False)
   
    For i=0 To TypeObjectsList.Size-1
        Dim bt As ObjectTypes = TypeObjectsList.Get(i)
        ObjectTypePopMenu.AddMenuItem(bt.title, "ObjectTypePopMenu")
    Next
 

Attachments

  • TESTE_FiltroTipoObjecto_Na_listagem_Objectos.PNG
    TESTE_FiltroTipoObjecto_Na_listagem_Objectos.PNG
    183.2 KB · Views: 145
Upvote 0

JohnC

Expert
Licensed User
Longtime User
What library is this menu from?

My thought that is there is a bug in the menu lib because it should be able to see that there is not enough room to pop-up "above" the label, so it should pop-up under the label. But for some reason it is not.

A work-around for this bug would be to create an invisible label and position it under/lower than the real label and initialize the menu based on the invisible label's position (which is lower on the screen so hopefully the menu will fit)
 
Last edited:
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK, apparently this is a known bug and another user came up with the same solution I did - create an invisible view and initialize the menu based on that view.

The same other user also posted some code to help him calculate the location of the "dummy" view.

So, it looks like you too will have to position the invisible view to a location (before showing the menu) that will make sure the entire menu can be seen when it is displayed.
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
OK, apparently this is a known bug and another user came up with the same solution I did - create an invisible view and initialize the menu on that view.

The other user posted some code to help calculate the location of the "dummy" view.

So, it looks like you too will have to position the invisible view to a location (before showing the menu) that will make sure the entire menu can be seen when it is displayed.

I had seen that other user's answer but was hopping that someone had a better solution :)
Thanks anyway
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Yeah, the solution is not elegant, but because the original developer is no longer supporting the lib, it's the only solution at this time.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
You also have to keep in mind that if you ever have a menu that is too big to fit because of either too many menu selections, or simply because the user set their device's default font size to "large" or "huge" (which will make each menu selection line take up more room on the display), you can run into problems because it appears that this menu lib also does not support "scrolling", so it will be impossible for the user to select certain menu items if they are off-screen.

My suggestion is instead of using that menu lib, you should try to use one of the below material dialog libs because I think one or both of them support displaying a list of options just like a pop-up menu and control is immediately returned to your app when the user clicks on an item (no need for them to click OK) - meaning that even though this is a dialog library, one of the modes can act like a pop-up menu - and as a bonus they support "scrolling" in case the number of selections is too big to fit on the screen:


The only potential side-effect is that these dialogs will pop-up in the middle of the screen and not as an offset to some other view. Which in my experience is not a problem with users.
 
Last edited:
Upvote 0
Top