Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why won't my BACK BUTTON work?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a short program to take me from a menu list to a form and back.
But my back button won't work. Can you tell me why? Thanks.

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class Testing extends MIDlet implements CommandListener {
private Command exitCommand = new Command("Exit", Command.EXIT, 2);
private Command goCommand = new Command("Go", Command.OK, 2);
private Command backCommand = new Command("Back", Command.BACK, 2);
private Display display;
private Alert resultAlert;
private List list;
public static final String[] items = {"Choice 1", "Choice 2", "Choice 3", "Choice 4"};
public Testing() {
display = Display.getDisplay(this);
list = new List("", List.IMPLICIT, items, null);
list.addCommand(exitCommand);
list.addCommand(goCommand);
list.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
display.setCurrent(list);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
int len, i;
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
} else if (c == goCommand) {
Form resultSet = new Form("Results of Your Search");
String[] strings = {"Here is a page", "written by a sage"};
len = strings.length;
for (i=0; i<len; i++ ) {
resultSet.append(strings[i] + "\n");
}
resultSet.addCommand(backCommand);
display.setCurrent(resultSet);
}
}
}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe it needs to see a Chiropractor?

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, because there is no code in the commandAction method to handle the user selecting the command


BACK

public static final int BACK

A navigation command that returns the user to the logically previous screen. The jump to the previous screen is not done automatically by the implementation but by the commandAction provided by the application. Note that the application defines the actual action since the strictly previous screen may not be logically correct.
Value 2 is assigned to BACK.

See Also:



Mark
 
ruffy me
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark!
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic