Confusedly with team listeners and new J2ME forms

The EDIT: . I think I need help getting the selected item from the list, which I just managed. to display a new form, but I have a lot of problems finding code that works with source 3.0.


I am trying to create an application that allows the user to select a date and then add and delete events based on the selected date. So far I have created the first screen
which is a list of options for the user to choose from.
These parameters are:

  • Choose a date
  • Add Events
  • Delete events
  • Event Overview

The problems I am facing, I can’t figure out how to display new forms based on the item you selected in the list. I found a small tutorial that allowed me to add a listener command that displays the selected item, but I find it difficult to understand how it gets the item selected in the list, and how can I create a new form based on the selected item?

Here is my code so far.

    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.List;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.MIDlet;

    public class mainMidlet extends MIDlet implements CommandListener {

      private Display display;
      private List list = new List("Please Select a Option", List.IMPLICIT);
      private Command select = new Command("Select", Command.SCREEN, 1);
      private Form form;
      Alert alert;

      public mainMidlet() {
        display = Display.getDisplay(this);   

        list.append("Select Date", null);
        list.append("Add Events", null);
        list.append("Remove Events", null);
        list.append("Browse Events", null);
        list.addCommand(select);
        list.setCommandListener(this);

      }

      public void startApp() {
        display.setCurrent(list);
      }

      public void pauseApp() {
      }

      public void destroyApp(boolean unconditional) {
      }

      public void commandAction(Command command, Displayable displayable) {
        if (command == List.SELECT_COMMAND) {
          String selection = list.getString(list.getSelectedIndex());
          alert = new Alert("Option Selected", selection, null, null);
          alert.setTimeout(Alert.FOREVER);
          alert.setType(AlertType.INFO);
          display.setCurrent(alert);
        } else if (command == select) {
          destroyApp(false);
          notifyDestroyed();
        }
      }
    }
+3
source share
1 answer

You can add multiple forms and switch between them.

  public void commandAction(Command command, Displayable displayable) {
      if (displayable == list) {
          if (command == List.SELECT_COMMAND) {
              switch (list.getSelectedIndex()) {
                  case 0: // select date
                      display.setCurrent(someForm);
                      break;
                  case 1: //add events
                      display.setCurrent(someOtherForm);
                      break;
              }
          } else if (command == select) {
             destroyApp(false);
             notifyDestroyed();
          }
      }
      if (displayable == someForm) {
          //but it better practice to make each form a different class implementing CommandListener and it own commandAction. And leave the display public static in MIDlet class
          //...
      }
  }
+4
source