java - invoking native MenuItem(Switch Application, Close, etc.) in my CustomMenu in blackberry -


i need create custom menu in blackberry application can manage appearance. managed create custom menu creating class extends popupscreen , having menuitem customized labelfield abstract invokeaction() method. made invokeaction() method abstract emulate run() method of menuitem.

enter image description here

everything ok remember something. if boss ask me implement native menuitems switch application , close. don't think implementing close problem, switch application , other native menuitem show keyboard, give me problem. come solution , code:

public custommenu(mainscreen screen) {         super(vfm);         menu menu = screen.getmenu(0);         for(int = 0; < menu.getsize(); i++){             final menuitem finalmenu = menu.getitem(i);             vfm.add(new custommenuitem(finalmenu.tostring(), field.focusable){                 protected boolean invokeaction(int action) {                     finalmenu.run();                     return true;                 }             });         }     } 

this constructor of custommenu. accept instance of mainscreen parameter the lists of menuitem , add existing custommenu. invokeaction() overridden method there counterpart of run() method of menuitem. , result of did:

enter image description here

i managed put native menuitem in custommenu problem when invoke(click) native menuitem(switch application, close) got illegalstateexception. there way implementation of native menuitem? or way capture run() method of menuitem invoke in custommenu?

update

after getting more clarification op, believe correct answer cannot they're asking ... create own menu, , programmatically invoke menuitem commands/actions built-in menu.


original answer

if understand correctly, want create own menu, don't want use built-in blackberry menu, because menu needs different?

if case, suggest approach. think way blackberry wants add menuitem objects built-in menu normally, change various properties of menu in screen class's makemenu() method:

protected void makemenu(menu menu, int context) 

here the blackberry docs on doing this, , here example combines adding menu items show above, changes menu appearance. hopefully, find easier way want, doesn't involve having link menuitems built-in menu, yours:

public class menuscreen extends mainscreen {    private background _menubackground;    private border _menuborder;    private font _menufont;    private menuitem _custommenuitems[];     public menuscreen() {       settitle("custom menu sample");       getmainmanager().setbackground(backgroundfactory.createsolidbackground(color.black));        richtextfield f = new richtextfield("creating custom menu") {                              protected void paint(graphics g) {             int oldcolor = g.getcolor();             g.setcolor(color.white);             super.paint(g);             g.setcolor(oldcolor);          }       };       add(f);        // customize (border/color/font) of bb menu here:       xyedges thickpadding = new xyedges(10, 10, 10, 10);       _menuborder = borderfactory.createroundedborder(thickpadding, border.style_dotted);               _menubackground = backgroundfactory.createsolidtransparentbackground(color.darkmagenta, 80);        try       {          fontfamily family = fontfamily.forname("bbcasual");          _menufont = family.getfont(font.plain, 30, ui.units_px);       }       catch (final classnotfoundexception cnfe)       {          uiapplication.getuiapplication().invokelater(new runnable()          {             public void run()             {                dialog.alert("fontfamily.forname() threw " + cnfe.tostring());             }          });                     }               // add our own menu items,       _custommenuitems = new menuitem[3];       _custommenuitems[0] = new menuitem("hola dora!", 110, 10) {          public void run() {             dialog.inform("hola dora!");          }       };       _custommenuitems[1] = new menuitem("close popup!", 111, 10) {          public void run() {             dialog.inform("close popup!");          }       };       _custommenuitems[2] = new menuitem("hola diego!", 112, 10) {          public void run() {             dialog.inform("hola diego!");          }       };        addmenuitem(_custommenuitems[0]);       addmenuitem(_custommenuitems[1]);       addmenuitem(_custommenuitems[2]);          }     protected void makemenu(menu menu, int context)    {       menu.setborder(_menuborder);       menu.setbackground(_menubackground);       menu.setfont(_menufont);       // invoking super.makemenu() add {close, switch application, etc.} items       super.makemenu(menu, context);    } } 

results

enter image description here

note: if have support os 6.0 , above, have other options, (let know). also, it's possible motivation writing own menu because want change font color, don't think can code show above. again, if that's part of design, please let know. thanks.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -