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
Developer
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Change text of menu item.

Hello all,

          I want to change the text of menu item in the menu added to a screen. I have added the menu items to the menu overriding makeMenu(), code is given below:

                                           

protected void makeMenu(Menu menu, int instance) {
        super.makeMenu(menu, instance);
        if(!mIsRelatedStory){
            menu.add(new MenuItem("A", 0, 1) {
                
                public void run() {
                   //Code
                }
            });
        }
        
        menu.add(new MenuItem("B", 0, 2) {
            
            public void run() {
                // TODO Auto-generated method stub
            }
        });
        
        menu.add(new MenuItem("C", 0, 3) {
            
            public void run() {
                // TODO Auto-generated method stub
                
            }
        });
        
        menu.add(new MenuItem("D", 0, 4){
            public void run() {
               //TODO
            };
        });
        
    }

 

Now  I want to change the text of menu item "D" to "E", when clicked on it and i need to save that status i.e. text to remain as "E", if I revisit the screen again and if clicked on it back, the text has to be changed back to "D" and again have the status saved.

I went though some of the posts in forums, but could not get appropriate answer for my problem. Can someone throw light on the problem? Thanks in advance..

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Change text of menu item.

There are two issues here:

a) How to store a value persistently

b) how to use that value as text in a menu item.

 

The second is easy, you can set the Text in makeMenu as you currently do, but rather than setting it to a literal, you can set to the value you have saved.  So the only trick is saving a value and getting it back.

 

If you search for "persistent" you will find a number of KB articles and tutorials that will help, including this one:

http://supportforums.blackberry.com/t5/Java-Development/Introduction-to-Persistence-Models-on-BlackB...