BlackBerryForums.com : Your Number One BlackBerry Community      

»Sponsored Links



Closed Thread
 
LinkBack Thread Tools
  (#1 (permalink)) Old
srp336 Offline
New Member
 
Posts: 10
Join Date: Sep 2005
Model: 7250
Default Listfield with Context Menus - need code sample - 11-08-2005, 07:15 PM

I've got an app I'm working on with a listfield. I'd like to add context menus when the user clicks the trackwheel on certain lines of that listfield. The context menus would need to include some of the text of the line in question. Is there some sample code I could look at to help with this?

Thanks!
   
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
ecarmody Offline
Thumbs Must Hurt
 
Posts: 80
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 8100
Carrier: Cingular
Default 11-17-2005, 04:10 PM

I dont' know about an actual "context" sensative menu (I have actually built any), but if you use the makeMenu(Menu menu, int instance) event of your screen, then when it is called, in there you can check to see if your listfield has focus, and if so, get text from the current line, and build a menu item on the fly.

Example of the MenuItem class and the makeMenu event ...

Code:
private class DynamicMenuItem extends MenuItem
    {
        private String menuName;
        
        public DynamicMenuItem()
        { 
            super("(na)",100,10); //don't call the constructor
        }
        public DynamicMenuItem(String menuText)
        {
            super(menuText,100,10);
            menuName = menuText;
        }
        
        public void run()
        {
            foo(menuName);
        }
    }

protected void makeMenu(Menu menu, int instance)
    {
        menu.addSeparator();
        
        //dynamically add menu items
        DynamicMenuItem newMenu = new DynamicMenuItem(listField.getCurrentText());
        menu.add(newMenu);
        
        menu.addSeparator();
        super.makeMenu(menu, instance);
    }
This should get you going.
Cheers,
Eric
   
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On






Copyright © 2004-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1