×

Discussion Board

Results 1 to 2 of 2

Thread: Iterating forms

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    48

    Iterating forms

    how can i use iteration between different forms.
    guide me with a sample code.
    I have a sample code which navigates between different forms like this one.
    but incase i need to have many forms, i have to write many lines of code.
    so i hope the iteration could help.

    public class NavigationMIDlet extends MIDlet implements CommandListener {
    private Form firstScreen;
    private Form secondScreen;
    private Form thirdScreen;

    // Navigation commands
    private static final Command NEXT_COMMAND =
    new Command("Next", Command.OK, 1);
    private static final Command PREV_COMMAND =
    new Command("Previous", Command.BACK, 1);
    private static final Command EXIT_COMMAND =
    new Command("Exit", Command.EXIT, 1);;

    /**
    * Constructor. Constructs the object and initializes displayables.
    */
    public NavigationMIDlet() {
    // Initialize the screens
    initFirstScreen();
    initSecondScreen();
    initThirdScreen();
    }

    private void initFirstScreen() {
    firstScreen = new Form("First example screen");
    StringItem item = new StringItem("Description",
    "This is the first example screen.");
    firstScreen.append(item);
    firstScreen.addCommand(NEXT_COMMAND);
    firstScreen.addCommand(EXIT_COMMAND);
    firstScreen.setCommandListener(this);
    }

    private void initSecondScreen() {
    secondScreen = new Form("Second example screen");
    StringItem item = new StringItem("Description",
    "This is the second example screen.");
    secondScreen.append(item);
    secondScreen.addCommand(NEXT_COMMAND);
    secondScreen.addCommand(PREV_COMMAND);
    secondScreen.setCommandListener(this);
    }

    private void initThirdScreen() {
    thirdScreen = new Form("Third example screen");
    StringItem item = new StringItem("Description",
    "This is the third example screen.");
    thirdScreen.append(item);
    thirdScreen.addCommand(PREV_COMMAND);
    thirdScreen.setCommandListener(this);
    }

    private void switchCurrentScreen(Displayable displayable) {
    Display.getDisplay(this).setCurrent(displayable);
    }

    /**
    * From MIDlet.
    * Called when the MIDlet is started.
    */
    public void startApp() {
    // The initial display is the first form
    switchCurrentScreen(firstScreen);
    }

    /**
    * From MIDlet.
    * Called to signal the MIDlet to enter the Paused state.
    */
    public void pauseApp() {
    // No implementation required
    }

    /**
    * From MIDlet.
    * Called to signal the MIDlet to terminate.
    * @param unconditional whether the MIDlet has to be unconditionally
    * terminated
    */
    public void destroyApp(boolean unconditional) {
    // No implementation required
    }

    /**
    * From CommandListener.
    * Called by the system to indicate that a command has been invoked on a
    * particular displayable.
    * @param command the command that was invoked
    * @param displayable the displayable where the command was invoked
    */
    public void commandAction(Command command, Displayable displayable) {
    if (command == EXIT_COMMAND) {
    // Exit the MIDlet
    notifyDestroyed();
    } else if (command == NEXT_COMMAND) {
    if (displayable == firstScreen) {
    switchCurrentScreen(secondScreen);
    } else if (displayable == secondScreen) {
    switchCurrentScreen(thirdScreen);
    }
    } else if (command == PREV_COMMAND) {
    if (displayable == secondScreen) {
    switchCurrentScreen(firstScreen);
    } else if (displayable == thirdScreen) {
    switchCurrentScreen(secondScreen);
    }
    }
    }
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,772

    Re: Iterating forms

    Note that it is possible to create separate Form-based classes, see articles like http://developer.nokia.com/community...ierarchy:_Form or http://developer.nokia.com/community..._use_two_forms for some ideas. Then creating the fields and configuring the menu for each form will be hosted in the own class of the given form, and also the CommandListener can be implemented there (then you will not have to check which form is visible for example, because you will get commands from the given form only).

Similar Threads

  1. Replies: 1
    Last Post: 2010-08-29, 22:43
  2. Replies: 0
    Last Post: 2007-08-03, 15:43
  3. problem of iterating the fields
    By Atl antis in forum Symbian
    Replies: 2
    Last Post: 2007-04-23, 09:51
  4. Replies: 7
    Last Post: 2007-03-12, 12:11
  5. iterating over phonebook entries
    By noamt in forum PC Suite API and PC Connectivity SDK
    Replies: 2
    Last Post: 2004-03-25, 15:38

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×