B4A Library RSPopupMenu

RSPopupMenu
Screenshot_2014-08-06-16-33-37.png

Click the picture to see the image.
RSPopupMenu wraps the native Android PopupMenu (API 11+) and attaches a PopUpMenu to a view.
You can add menu's or submenus and 2 events are called:

B4X:
public sub Initialize
dim PopupMenu As RSPopupMenu
'Initialize the PopupMenu
    PopupMenu.Initialize("PopupMenu", ivPopup)
    PopupMenu.AddMenuItem(0, 0, "View")
    PopupMenu.AddMenuItem(1, 1, "Edit")
    PopupMenu.AddMenuItem(2, 2, "Details")
    PopupMenu.AddMenuItem(3, 3, "Remove")
end sub

Sub ivPopup_Click
    PopupMenu.Show
 
End Sub

Sub PopupMenu_Dismiss
    ToastMessageShow("PopupMenu dismissed", False)
End Sub

Sub PopupMenu_MenuItemClick (ItemId As Int) As Boolean
    ToastMessageShow("Item " & ItemId & " clicked.", False)
    Return False
End Sub


RSPopupMenu

Author: XverhelstX
Version: 1
  • RSPopupMenu
    Methods:
    • AddMenuItem (ItemId As Int, Order As Int, Title As String)
      Add a new item to the menu.
    • AddMenuItem2 (GroupId As Int, ItemId As Int, Order As Int, Title As String)
      Add a new item to the menu.
    • AddSubMenuItem (ItemId As Int, Order As Int, Title As String)
      Add a new item to the menu.
    • AddSubMenuItem2 (GroupId As Int, ItemId As Int, Order As Int, Title As String)
      Add a new item to the menu.
    • Dismiss
      Dismiss the menu popup.
    • Initialize (EventName As String, view As ConcreteViewWrapper)
      Initializes the Popup Menu.
      A PopupMenu displays a Menu in a modal popup window anchored to a View.
      The popup will appear below the anchor view if there is room, or above it if there is not.
      If the IME is visible the popup will not overlap it until it is touched.
      Touching outside of the popup will dismiss it.
    • Initialize2 (EventName As String, view As ConcreteViewWrapper, Gravity As Int)
      Initializes the Popup Menu.
      A PopupMenu displays a Menu in a modal popup window anchored to a View.
      The popup will appear below the anchor view if there is room, or above it if there is not.
      If the IME is visible the popup will not overlap it until it is touched.
      Touching outside of the popup will dismiss it.
    • IsInitialized As Boolean
    • Show
      Show the menu popup anchored to the view specified during construction.

Kind regards,
Tomas
 

Attachments

  • RSPopupMenu.zip
    5.1 KB · Views: 1,717

WizardOz

Member
Licensed User
Longtime User
Great and lightWeight!
Any chance of getting some icons in the popuplist?
 

corwin42

Expert
Licensed User
Longtime User
Great and lightWeight!
Any chance of getting some icons in the popuplist?

The normal API11 PopupMenu class does not support Icons directly. Icon Support can be enabled with reflection in the normal Android PopupMenu class.
The PopupMenu implementation of the StdActionBarHelper library supports icons but is slightly more complicated to use (because you need to handle Menu and Menuitem objects, too)
 

WizardOz

Member
Licensed User
Longtime User
Thx for the answer. Loved the easy and lightweight of this!
 

aaronk

Well-Known Member
Licensed User
Longtime User
How would you remove a item from the menu once it's created ?

I am creating the menu from Activity_Create and then calling the menu when I press a button on the page.
I am creating the menu like:
B4X:
 PopupMenu.Initialize("PopupMenu", ivPopup)
 PopupMenu.AddMenuItem(0, 0, "View")
 PopupMenu.AddMenuItem(1, 1, "Edit")
 PopupMenu.AddMenuItem(2, 2, "Details")
 PopupMenu.AddMenuItem(3, 3, "Remove")

How would you remove lets say 'Edit' from the menu ?

Would you just need to re-initialize it again and re-create the menu again? Could I move the code from Activity_Create which is creating the menu and put that code in the button_click section ?
 

skipsy

Member
Licensed User
Longtime User
Hi,
I feel a bit stupid but when compiling I get :
Undeclared variable 'ivpopup' is used before it was assigned any value.
PopupMenu.Initialize("PopupMenu", ivPopup)

your method says
B4X:
Initialize (EventName As String, view As ConcreteViewWrapper)

ConcreteViewWrapper type looks unknown...
The usersGuide (1.4) does not mention it !!
What did I missunderstood ???

Thks,
WW
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Hi,
I feel a bit stupid but when compiling I get :
Undeclared variable 'ivpopup' is used before it was assigned any value.
PopupMenu.Initialize("PopupMenu", ivPopup)

your method says
B4X:
Initialize (EventName As String, view As ConcreteViewWrapper)

ConcreteViewWrapper type looks unknown...
The usersGuide (1.4) does not mention it !!
What did I missunderstood ???

Thks,
WW


ivPopup is the view that you want your popmenu to be close to. so if it is a button that you click to popup the meny then change ivPopup to the buttons name
 

skipsy

Member
Licensed User
Longtime User
Ok I understand the way it works now.
I realized I could have an idea with the method description
  • Show
    Show the menu popup anchored to the view specified during construction.

So I now have a button to anchor the popup :
B4X:
Public Sub Initialize
Dim PopupMenu As RSPopupMenu
'Initialize the PopupMenu
  PopupMenu.Initialize("PopupMenu", Button1)
  PopupMenu.AddMenuItem(0, 0, "View")
  PopupMenu.AddMenuItem(1, 1, "Edit")
  PopupMenu.AddMenuItem(2, 2, "Details")
  PopupMenu.AddMenuItem(3, 3, "Remove")
End Sub

Sub Button1_Click
    PopupMenu.Show
End Sub
and the message
Undeclared variable 'popupmenu' is used before it was assigned any value.
PopupMenu.Show

But "popupmenu" has actually been declared :eek::eek::eek:
WW
 

skipsy

Member
Licensed User
Longtime User
Of course !!!!!!!!!!!!!!!!!!!!!
I just did a stupid copy/paste of the post for test ...:rolleyes:
Thks.
 

skipsy

Member
Licensed User
Longtime User
Damn !! sounds this lib does not work with my B4A version (3.0).
Dim PopupMenu As RSPopupMenu returns the message
"The application ... has stopped unexpectedly. Please try again.
WW
 

skipsy

Member
Licensed User
Longtime User
Me again...
Problem solved !
Not due to the core 3.0 but the emulator API 2.3.3 :p
 

ivan.tellez

Active Member
Licensed User
Longtime User
Hi, Well, its a great lib.

An of course, it only works with android 3+, but in lower api, the app crashes jus by doing the DIM.

Could you please make this lib more flexible? somthing like, check if its on api 10 or below and if this is the case just does nothing to prevent the app from crashing.

Thanks
 

JonRubin

Member
Licensed User
Longtime User
Great Work! I have 2 questions... 1) How can I clean the Popup Menu? 2) Can I retrieve the Title Text based on the ItemId Returned or something like in vb.net List.SelectedText ? Thanks
 

jcesar

Active Member
Licensed User
Longtime User
Great lib !!

But when i try use with a list like UltimateListView the popup is displayed out of place. See picture when i touch in the first line:

popup.png
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
B4X:
AddMenuItem (ItemId As Int, Order As Int, Title As String) Add a new item to the menu.

AddSubMenuItem (ItemId As Int, Order As Int, Title As String) Add a new item to the menu.
AddSubMenuItem2 (GroupId As Int, ItemId As Int, Order As Int, Title As String) Add a new item to the menu.

AddMenuItem works fine. What does AddSubMenuItem and AddSubMenuItem2 do?

When I called ALL they do is the same thin AddMenuItem does which is add a menuitem

I though they would create a sub sub menuitem

BobVal
 

JonRubin

Member
Licensed User
Longtime User
Hi... Does anyone know that answer to #2 in Post 16.... 2) Can one retrieve or access the Title Text based on the ItemId Returned or something like in vb.net List.SelectedText?

Thanks!
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
B4X:
	Type     TMenuItems(MenuItemID As Int, OrderNumber As Int, GroupID As Int, MenuItem As String, WebLink As String)

When adding my menuitems I create a type containing all the information and save it in a list and use the ItemId to retrieve the entry when selected
 
Top