I'm programming a J(2)ME app (actually a MIDlet) where more commands than command buttons available are shown on the screen and I'm stuck with this situation:
The mapping to concrete user interface constructs may also depend on the total number of the commands. For example, if an application asks for more abstract commands than can be mapped onto the available physical buttons on a device, then the device may use an alternate human interface such as a menu. For example, the abstract commands that cannot be mapped onto physical buttons are placed in a menu and the label "Menu" is mapped onto one of the programmable buttons.
So in this situation a Menu is auto-generated and a 'Select' and 'Back' choice added. The 'Back' choice is supposed to exit the menu and go back to the previous screen. This works in principle, problem is I need to catch it somehow and trigger a redraw, otherwise the screen goes blank.
So my question is: Is there a way to catch this 'implicit' (automatically added 'Back' command ?
Code example and result:
public class HelloWorld extends MIDlet
{
private Form helloFrm;
private Display display;
public HelloWorld() {
Command command1 = new Command("Cmd 1", Command.SCREEN, 1);
Command command2 = new Command("Cmd 2", Command.SCREEN, 0);
Command command3 = new Command("Cmd 3", Command.SCREEN, 0);
Command command4 = new Command("Cmd 4", Command.SCREEN, 0);
helloFrm = new Form("Hello World");
helloFrm.addCommand(command1);
helloFrm.addCommand(command2);
helloFrm.addCommand(command3);
helloFrm.addCommand(command4);
}
public void startApp()
{
display = Display.getDisplay(this);
display.setCurrent(helloFrm);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
}
edit to add more detail:
As per my comment, I'm going back from a Form to Canvas in my app, that's where the screen blanking happens. I've already added my own 'Back' command, this one works correctly as I can catch easily with CommandListener and treat accordingly (trigger a redraw). But now I have two 'Back' commands, the implicit one (blanking) and mine. So the alternative version of the question is: Can I prevent the adding of the implicit 'Back' command somehow ?
You can't prevent the adding of the implicit 'Back' command, but you can redraw the screen from the call to Canvas.showNotify:
The implementation calls showNotify() immediately prior to this Canvas being made visible on the display. Canvas subclasses may override this method to perform tasks before being shown, such as setting up animations, starting timers, etc. The default implementation of this method in class Canvas is empty.