Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 28
Registered: ‎01-26-2010
My Device: bold 9700
My Carrier: Vodafone UK

Application Menu Item "Remove from Local Application"

Hi,

 

i am creating an application and want to use icon on the menu items for v5+. i can create icons with menu for my application but not outsdie my app.

 

So as a work around i have icons for my app menu and then menu items for the global system(menu's outside my app) but without icons as i don't think that menu icons outside your app are supported.

 

the problem i have is i dont want the global menu item, to appear in my local app:

1. because the menu item within my app does not run(only when selecvted outside my app).

2.because i have menu icons in my app for the visual look. i end up with a duplicate menu item. one of which dose not work and has no functionality within the app and the other which works and has an icon.

 

So how do i remove the global menu item from the app(local) that create it.

 

code below for global menu

// Create global menu item
      int placement = 0x350100;
      ApplicationMenuItem ami = new ApplicationMenuItem(placement)
      {
         public Object run(Object context)
         {
             if (context == null) {
                    Dialog.alert("context is null -- is this a bug?");
                }
                else {
                    Dialog.alert("context not null");
                }
            checkAvailability();
            return null;
         }
         public String toString()
         {
            return "MyApp: Add ";
         }
      };

 

many thanks in advanced

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Application Menu Item "Remove from Local Application"

check the menu items in makeMenu, if it is already added there you can remove it, otherwise not.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 28
Registered: ‎01-26-2010
My Device: bold 9700
My Carrier: Vodafone UK

Re: Application Menu Item "Remove from Local Application"

thanks for the quick reply, i'm brand new to java and bb dev. a code example of what you are describing would be fantastic.
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Application Menu Item "Remove from Local Application"

as a second thought:

no need to remove anything, just don't add anything Smiley Happy

 

take a mainscreen. overwrite makeMenu. put menu.clear() in the first line, add your menu items, don't call super.makeMenu.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 28
Registered: ‎01-26-2010
My Device: bold 9700
My Carrier: Vodafone UK

Re: Application Menu Item "Remove from Local Application"

Hi,

 

i understand the logic of what you are saying but as i am a newbie to java period.

 

below i have paste in the code im using to implement menu so far.

 

public void AddIconScreen()
        {        
         Image menuIcon = ImageFactory.createImage(Bitmap.getBitmapResource("img.png"));
         _viewItem.setIcon(menuIcon);
         addMenuItem(_viewItem);
         _viewItem2.setIcon(menuIcon);
         addMenuItem(_viewItem2);
         
          // Register menu item to display when user views a contact
          ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
          amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_SYSTEM ,ami);
      }
        
      private MenuItem _viewItem = new MenuItem("Check Availabitiy", 110, 10)
      {
             public void run()
             {
                 checkAvailability();
             }
      };
      private MenuItem _viewItem2 = new MenuItem("Clear", 1, 10)
      {
             public void run()
             {
                 clearTextFields();
             }
      };
    
    // Create global menu item
      int placement = 0x350100;
      ApplicationMenuItem ami = new ApplicationMenuItem(placement)
      {
         public Object run(Object context)
         {
             if (context == null) {
                    Dialog.alert("context is null -- is this a bug?");
                }
                else {
                    Dialog.alert("context not null");
                }
            checkAvailability();
            return null;
         }
         public String toString()
         {
            return "MYapp: Add ";
         }
      };

 

With the above code i get two menu items added to my local app with icons and a system wide menu item added without an icon.

 

All i want to do is remove the system wide menuitem from my local app but still exist in all the other menu's outside of my app. modification of my code or a cleaner way to do the same would be much appreciated.

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Application Menu Item "Remove from Local Application"

overwrite makeMenu (assuming you use MainScreen)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 28
Registered: ‎01-26-2010
My Device: bold 9700
My Carrier: Vodafone UK

Re: Application Menu Item "Remove from Local Application"

Hi,

 

i don't use makemenu in my code....the code i have shown previouly is what i use to make the menu's. It would be great if you could either show an complete example or modify the code i have listed.

 

i have read loads on java and blackberry development but allot of it is inconsistant or hard to match up with other code examples. my point being i can make a menu item with an icon for my app but not a global menu item with an icon.

 

many thanks for you time and help so far

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Application Menu Item "Remove from Local Application"

 

try getMenu().deleteAll() before adding your menu items, this should work without overwriting makeMenu

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter