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
Contributor
Posts: 15
Registered: ‎09-06-2010
My Device: Not Specified
Accepted Solution

Disable Default Context Menu

[ Edited ]

I have a screen which contains some LabelField(s) that are FOCUSABLE. I want to override the default Context Menu & add ONLY two menu items "Open" & "Delete". I'm using the following code:

 

protected void makeMenu(Menu menu, int instance) {

     Field focus = UiApplication.getUiApplication().getActiveScreen().getLeafFieldWithFocus();

 

     if (  (focus != null)  &&  (focus instanceof LabelField)  ) {            
            menu.add(new MenuItem("Delete Item", 10, 20) {
                public void run() {
                    delete_item();
                }
            });
            menu.add(new MenuItem("Open", 20, 10) {
                public void run() {
                    open();
                }
            });   
   
     }

}

 

But I'm still getting the "Copy" option when the LabelField gets the focus. Is there something wrong with this code?

Developer
Posts: 192
Registered: ‎01-12-2010
My Device: Bold
My Carrier: ZAIN

Re: Disable Default Context Menu

try making the labelfield isEditable = false

may be it will work

Contributor
Posts: 15
Registered: ‎09-06-2010
My Device: Not Specified

Re: Disable Default Context Menu

I tried that, but its not working.

Developer
Posts: 192
Registered: ‎01-12-2010
My Device: Bold
My Carrier: ZAIN

Re: Disable Default Context Menu

protected void makeMenu(Menu menu, int instance)    
		 {       
			 menu.add(new MenuItem("FONT SETTINGS" , 100, 10)       
			 {         
				 public void run(){
					 UiApplication.getUiApplication().invokeAndWait(new Runnable() 
			            {                
			                public void run() 
			                {
			                	
			                    UiApplication.getUiApplication().pushScreen(new FontChange());

			                }
			            });
				 }
			 });

 the above code works for me

but why u using

Field focus = UiApplication.getUiApplication().getActiveScreen()​.getLeafFieldWithFocus();

 

but if you select any labelfield it will give you copy option

 

do one thing override the buttonfield class and create your own button and then use the .consumeclick method

 

hope this will help u

Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: Disable Default Context Menu

didu tried this:

 

    if (  (focus != null)  &&  (focus instanceof LabelField)  ) {            
            menu.add(new MenuItem("Delete Item", 10, 20) {
                public void run() {
                    delete_item();


                    return true;  // works like consume_click of button

               }
            });

 

i saw this at some place may be it works

Contributor
Posts: 15
Registered: ‎09-06-2010
My Device: Not Specified

Re: Disable Default Context Menu

In addition to the LabelFields, I have some buttons on the screen which are FOCUSABLE by default. But I want my menu items "Open" & "Delete" to appear only when the LabelField gets focus.

 

That is the reason why I used:

 

Field focus = UiApplication.getUiApplication().getActiveScreen()​.getLeafFieldWithFocus();

 

if (  (focus != null)  &&  (focus instanceof LabelField)  ) {  

.....

 

}

 

 

If I use the following code as suggested

 

public void run() {
                    delete_item();


                    return true;  // works like consume_click of button

               }

 

then it is giving compile error "cannot return a value from method whose result type is void"

Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: Disable Default Context Menu

yes it will return compile time error as i assumed it to be navigation click instead of menu

 

extremly sorry, let me see this qustion once again

Developer
Posts: 147
Registered: ‎08-27-2010
My Device: 9800
My Carrier: airtel

Re: Disable Default Context Menu

try this

 

protected void makeMenu(Menu menu, int instance) {
     Field focus = UiApplication.getUiApplication().getActiveScreen().getLeafFieldWithFocus();
 
     if (  (focus != null)  &&  (focus instanceof LabelField)  ) {   
            menu.deleteAll();         
            menu.add(new MenuItem("Delete Item", 10, 20) {
                public void run() {
                    delete_item();
                }
            });
            menu.add(new MenuItem("Open", 20, 10) {
                public void run() {
                    open();
                }
            });   
   
     }
}