View Single Post
  (#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, 05: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