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
New Developer
mrmarkwang
Posts: 27
Registered: ‎08-26-2008
My Device: Not Specified

How to turn some contextmenu off?

[ Edited ]

In my program, ther have a EditField object, after i input some chars into it, and i press the menu,

 

In the menu, there have some contextmenu such as 'select', 'check spelling','clear field', 'show symbols'. I don't want these menuitem in the menu, 

 

I override makemenu(Menu menu, int instance) but it doesn't work.

 

 

Message Edited by mrmarkwang on 09-07-2008 09:26 PM
Please use plain text.
Developer
rafo
Posts: 507
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to turn some contextmenu off?

override makeMenu() method in your screen class. And add only necessary items to the menu.
----------------
if your issue solved set "Solution" mark at the relevant post
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to turn some contextmenu off?

Have you used the debugger to prove that you are actually going through your overridden makeMenu?

 

If you have overridden it correctly, the context sensitive menu parts will be added by the super.makeMenu(), so you can comment this out to suppress these.

 

There are additional articles about context menus in the KnowledgeBase.  I suggest that you review these for more information.

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe

Please use plain text.
New Developer
mrmarkwang
Posts: 27
Registered: ‎08-26-2008
My Device: Not Specified

Re: How to turn some contextmenu off?

[ Edited ]

I do override the makeMenu(Menu menu, int instance), and I debug it ,found it has been executed.

It's wired that my own menus have been added,  and i don't add any other menus ( i don't use super.makemenu() at all).

I post my programs . Maybe someone could help me out.

 

1.MainApp.java

 

package TestMenu;
import net.rim.device.api.ui.UiApplication;

public final class MainApp extends UiApplication
{   
    public static void main(String[] args)
    {
        MainApp mainApp = new MainApp();
        mainApp.enterEventDispatcher();
    }   
   
    public MainApp()
    {   
        MyScreen myScreen = new MyScreen();
        pushScreen(myScreen);       
    } 
}

2. MyScreen.java

 

package TestMenu;

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.*;


public final class MyScreen extends MainScreen{
    private EditField phoneNumberEdit;          // Phone Number Edit
   
    public MyScreen()
    {
        LabelField title = new LabelField("TestMenu" , LabelField.USE_ALL_WIDTH);
        setTitle(title);

        phoneNumberEdit = new EditField("Phone Number:" , "", 10, EditField.USE_ALL_WIDTH| EditField.NO_NEWLINE );   
        add(phoneNumberEdit);           
    }

    protected void makeMenu(Menu menu, int instance) {
        menu.add(saveItem);
        menu.add(eraseItem);
        menu.add(exitItem);
   }
   
    private MenuItem saveItem = new MenuItem("Save", 100, 10) {
        public void run() {}       
    };
   
    private MenuItem eraseItem = new MenuItem("Erase", 200, 10) {
        public void run() {}
    }; 
   
    private MenuItem exitItem = new MenuItem("Exit", 200000000, 10) {
        public void run() {}
    };
   
}

 

 

I use JDE4.5 in simulator

Message Edited by mrmarkwang on 09-08-2008 10:16 AM
Please use plain text.
New Developer
mrmarkwang
Posts: 27
Registered: ‎08-26-2008
My Device: Not Specified

Re: How to turn some contextmenu off?

I do some test, first i override makeContextMenu(ContextMenu contextMenu) without anything.

protected void makeContextMenu(ContextMenu contextMenu)
{
}

 

it dosen't work.

 

second, I add somethings in makeMenu(Menu menu, int instance) to find what the result is. the result is:  it add same context menus twice.

 

    protected void makeMenu(Menu menu, int instance) {


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

if(focus != null)
        {
            ContextMenu contextMenu = focus.getContextMenu();
            if(!contextMenu.isEmpty())
            {
                menu.add(contextMenu);
                menu.addSeparator();
            }
        }
        
        menu.add(saveItem);
        menu.add(eraseItem);
        menu.add(exitItem);
   }

 

the conclusion: I cannot control the context menu in JDE 4.5. maybe it's a bug.

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How to turn some contextmenu off?

Are you overriding makeContextMenu on the field that has focus, or on the screen?  The screen should be calling the field's makeContextMenu method.

 

Alternatively, you can just remove the section of code in makeMenu that is adding the context menu to the menu.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
mrmarkwang
Posts: 27
Registered: ‎08-26-2008
My Device: Not Specified

Re: How to turn some contextmenu off?

[ Edited ]
I override makeContextMenu on the screen , not on the field
Message Edited by mrmarkwang on 09-08-2008 01:04 PM
Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How to turn some contextmenu off?

That is the reason.  The context menu items you are referring to are coming from the EditField, not from the screen.  Therefore overriding makeContextMenu on the screen would not have any affect on these items.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.