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
Developer
Andiamo
Posts: 39
Registered: ‎05-26-2009
My Device: BlackBerry Storm 9550
Accepted Solution

How can I disable the default ContextMenu?

[ Edited ]
Hi,

I've been learning BlackBerry development and I'm in the middle of writing my first major app. On my app's main menu (or on any screen extended from MainScreen, in fact) when I click on a part of the screen that does not contain a control a menu appears with the options Switch Application, Show Keyboard, Close, and Full Menu.

 

I do not want to remove these from the regular menu that appears when you press the BB key, I just want to stop that contextmenu from popping up when you click the screen. I've tried setting NO_SYSTEM_MENU_ITEMS in the screen's constructor but that does two things I don't want: the default menu items are removed from the BBKey menu, and the context menu still pops up with only the item "Full Menu".

 

Is there any way I can just disable the contextmenu from appearing? I've tried to override makeContextMenu but that doesn't seem to have any effect.

 

Thanks

Message Edited by Andiamo on 05-26-2009 03:53 PM
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How can I disable the default ContextMenu?

Just override  makeMenu.

 

protected void makeMenu( Menu menu, int instance ) { //will show the default menu super.makeMenu(menu, instance); }

 

Also see KB article:

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/... 

 

 

Regards

Bikas 

Please use plain text.
Developer
Andiamo
Posts: 39
Registered: ‎05-26-2009
My Device: BlackBerry Storm 9550

Re: How can I disable the default ContextMenu?

[ Edited ]
Thanks for the advice. I just tried overriding makeMenu too and it only removes the Full Menu and Close options, while still allowing the context menu to show. I tried overriding makeMenu while at the same time applying the NO_SYSTEM_MENU_ITEMS flag and I still get a context menu, this time with a single item, "<Empty Menu>". It looks like my request is simply not meant to be, as that dumb menu will do whatever it takes to show up even if there's nothing in it. I can deal with it, though it is annoying.

 

Thanks for the help, anyway.

 

Message Edited by Andiamo on 05-26-2009 05:00 PM
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How can I disable the default ContextMenu?

I think there might be an easier way to remove this "<Empty Menu>".

 

I can suggest you an alternative by implenting TrackwheelListener.

 

 

import net.rim.device.api.system.TrackwheelListener;

 

class TestScreen extends MainScreen implements TrackwheelListener { TestScreen() { } protected void makeMenu( Menu menu, int instance ) { //super.makeMenu(menu, instance);

}

 

public boolean trackwheelClick( int status, int time ) { return true; } public boolean trackwheelUnclick( int status, int time ) { return true; } public boolean trackwheelRoll(int amount, int status, int time) { return true; } }

 

Regards

Bikas 

 

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can I disable the default ContextMenu?

Just want to clarify a few things, because I'm worried we are not understanding your problem properly.

 

When one says contextmenu, I usually take that to mean the menu that is associated with the context, i.e. the thing in focus.  So for example, when an Edit Field is in focus, a contextmenu will include 'Clear Field'. 

 

However in this case, this is not what you seem to mean.  The context menu that you are talking about here appears to the the menu that is invoked when you press the trackball.  This is not a Field specific context menu. 

 

I think you can suppress this menu in two ways:

 

1) Override navigationClick, but I'm not actually sure where you want to do this.

 

2) Have your makeMenu check the instance (the second parameter).  The trackball lick invocation has a different value, sorry can't remember what it is.  But the menu key invocation has a 0.  So for non 0 instance, don't caller super.makeMenu, and this will suppress the default menu items.

I suspect you want to use navigationClick, but I'm really not sure how to implement this and don't have time to test.  But stick one of these in your MainScreen and see when it gets invoked and what gets suppressed if you return true (which means that you have consumed the click). 

 

Hope this helps and/or clarifies a little.

Please use plain text.
Developer
Andiamo
Posts: 39
Registered: ‎05-26-2009
My Device: BlackBerry Storm 9550

Re: How can I disable the default ContextMenu?

I apologize for not being more clear; you are correct, the menu I was referring to was the menu that appears when the trackball (or in my case, touchscreen) is clicked, with nothing in focus. I called it a ContextMenu in my post simply because that's the object I figured it was. Sorry for the confusion.

 

At the moment I have pretty much solved the problem by overriding navigationClick, it turns out it was I needed to do it anyway for something else unrelated. Your makeMenu solution makes sense, I figured the instance argument would have something to do with how the menu was invoked but I never actually bothered to check the different values for BBKey/screen click.

 

Thanks to both of you for taking the time to help answer my question, I appreciate it. :smileyhappy:

Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: How can I disable the default ContextMenu?

Hi, peter_strange,

 

i did what you said, i mean i overriden the navigationClick in my mainscreen to disable the FullMenu option, but for me all the fields events get disabled. no event is firing on any field on the screen.

this is my code

 

protected boolean navigationClick(int status,int time){
       return true;
     }

 

Note: i didnt tested with return false.

 

Hi, Andiamo how did u disable FullMenu? can you post your code snippet here.

 

i tried with trackWheelListener also but of no luck. when am using trackWheelListener i didnt find any difference.

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
Andiamo
Posts: 39
Registered: ‎05-26-2009
My Device: BlackBerry Storm 9550

Re: How can I disable the default ContextMenu?

I was never able to really get the menu to go away via code. This was my first ever BlackBerry app, and so eventually I figured out that the contextMenu does not appear if the user clicks on a part of your screen that contains a field, be it a labelfield, bitmapfield, etc.

 

Most of my screens are pretty full so this ended up not being a problem for me. I know this isn't really going to answer your question though, sorry. :/

Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: How can I disable the default ContextMenu?

Hi Andiamo,

 

as you said i tried to fill my screen with the fields, for that i choose bitmapfield, previously i used paint method to set the background image, but according to your suggestion i used bitmapfield to fill my screen with a field.

 

But no luck!!!!!!

 

That FullMenu is still hunting me..... anybody there to help me to get rid of this!!!!

 

 

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
austinfrance
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: How can I disable the default ContextMenu?

[ Edited ]
deleted
Please use plain text.