How to refresh screen in BlackBerry? - blackberry

I use this on one of my screen:
protected void makeMenu(Menu menu, int instance){
if (UserData.sessionId != null){
menu.add(logOut);
menu.add(setting);
}
menu.add(exitApp);
}
The "log out" and "setting" menu only appear after the user logs in (hence, the session ID is not null).
How to make the "log out" and "setting" disappear from the menu after the user logs out, while the same screen is still being displayed?
invalidate() ?

makeMenu() should be called every time you press the menu button so you should not need to repaint. Is the UserData.sessionId being correctly updated once the user has logged out?
Also you should call super.makeMenu() when you override makeMenu()
I can't post a link to the java doc as I don't have enough reputation but that is mentioned in there.

Related

How to make content navigation button (remains pressed when clicked) in Vaadin

I created basic vertical layout that work as side menu and now I want to place some buttons in it. Few of them gonna work as common side menu buttons, they just change page content so I want to mark that they are clicked in some way, how can I achive that? Or maybe there is better way?
As stated in the 5th version of Vaadin7 manual, you can attach an event listener to the Button.
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// show the button has been clicked with a CSS class:
button.addStyleName("v-button-clicked");
}
});
Don’t forget to define the v-button-clicked class. Of course you’re free to add the class of your liking through the .addStyleName() method.

How to capture DialogViewController refresh in Xamarin.iOS?

I am using Xamarin to build a simple app. In my app I use a series of classes that inherit from DialogViewController. In some cases, when the user clicks on an item, I use:
NavigationController.PushViewController( new DialogViewClass() , true );
This when the DialogViewClass() starts and sets up a new view, it might alter the state of the data that requires my current Dialog to be refreshed.
When the user finally backs out of the stack, and reshows my dialog, how do I capture "the event" that says my dialog is being redisplayed, so that I can update my view with current information?
Found my answer. In the class that inherits from DialogViewController, add this override:
override void ViewWillAppear( bool animated ) {
base.ViewWillAppear( animated );
// Show the page
}
In my case, simply rebuilding the interface based on the values in my constructor is good enough whether the page is being loaded for the first time, or is being reloaded after a POP action.

"Changes made" notifycation

in my application I have some screens with focusable custom buttons, wich pushing another screens with another focusable custom buttons and so on. When I press blackberry's "back" button anter pushing 2-3 screens, it sometimes appear notification with message "Changes made", and options "save", "discard" and "cancel". Why is this? How can I avoid it? all I did is moved focus and pressed buttons.
you can avoid this overriding onclose() and setdirty(false).
public boolean onClose() {
setDirty(false);
return super.onClose();
}

J2ME handleKeyReleased affecting DefaultCommand

I am having a bit of a problem with an app I'm developing for BlackBerry.
I have a series of Item objects on the screen, each with a DefaultCommand tied to it. Example
below:
...
cmdBrowse = new Command(temp.id,Command.ITEM,0);
mainList.setDefaultCommand(cmdBrowse);
mainList.setItemCommandListener(icl);
...
Previously just clicking on the item with the confirm button would run the proper command. No problem there.
Then I added the handleKeyReleased method to capture the BlackBerry's back button as follows:
protected boolean handleKeyReleased(int keyCode, int gameAction) {
if(keyCode==1769472) {
/*code to deal with back button*/
return true;
} else {
return false;
}
}
Now when I click on the mainList Item with the confirm button, it brings up the list of commands first and I have to click again to actually run the command. Two clicks where it used to be one.
So, is there a way to either:
A. Keep the single click behaviour while still being able to capture the back button with handleKeyReleased
or
B. Capture the back button in a different way ?
I ended up overlooking one very simple thing. All I had to do was call the superclass's handleKeyReleased method and everything worked perfectly.

Remove menu item on Blackberry

In my Blackberry application, I have screen with few menu items (created by myself in makeMenu()).
On this screen, sometimes I should remove two of this menu items.
But menu.deleteItem() method does not work.
How i can remove menu item in application menu, without recreate new instance of screen? Is it real for already constructed menu? Or mb I should refresh menu/screen someway?
Thanx.
The menu is drawn at the point it's selected so all I do is set conditions on anything that's not static, example below:
protected void makeMenu( Menu menu, int instance ) {
menu.add(staticMenuItem);
if (condition) menu.add(dynamicMenuItem);
}

Resources