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
Visitor
Posts: 1
Registered: ‎04-19-2010
My Device: 8900
My Carrier: MTS
Accepted Solution

Changing text of MenuItem on the go

Hello.

I'm trying to create toggeable MenuItem. My code is:

MenuItem trackingMenu = new MenuItem("Stop tracking", 100, 10) {
public void run() {
boolean tracking = device.getTracking();
device.setTracking(!tracking);
if(tracking){
this.setText("Stop tracking");
} else {
this.setText("Start tracking");
}
}
};

 

Device is indeed changing it's tracking state, but text on the trackingMenu doesn't. Is it possible to change text that way and where is my mistake?


Thanks,
   Andrey.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Changing text of MenuItem on the go

This needs to be done in the makeMenu() override, so that the text is changed every time the menu is displayed.

 

 

 

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

Re: Changing text of MenuItem on the go

I think I have changed text on a menu item in the way described.  However you must make sure that the screen, or more accurately, the MenuItem is NOT recreated.  If it is recreated, then you need to run code to set the state of the menu correctly.