Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1445
  • Last Modified:

J2ME - sending data from one screen to another (List Selection to populate previous screen)

I am trying to return the value I select from a list to the previous screen.  When I set the myData string during the selection it does not change the field value.  Here is my code:

Thanks


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloMIDlet extends MIDlet
        implements javax.microedition.lcdui.CommandListener {

    TextField dataEntry;
    Display display;
    Form form;
    Command cancel;
    Command login;
    private List lsDocument;    
    public String myData;
    int count;

    public String getMyData() {
        return myData;
    }

    public void setMyData(String myData) {
        this.myData = myData;
    }


    public HelloMIDlet()
    {
        count = count + 1;
        String s = new Integer(count).toString();
        setMyData(s);
        dataEntry = new TextField("Data Entry:", getMyData().toString(), 10, TextField.ANY);
        form = new Form("Login In");
        login = new Command("Login", Command.OK, 2);
    }
   

    public void commandAction(Command c, Displayable d) {      
         String label = c.getLabel();    
            if (label.equals("Login"))
            {
                menu();
            }
            else if (c == List.SELECT_COMMAND)
            {
              switch (lsDocument.getSelectedIndex())
              {
                case 0:
                setMyData("NEXT");
                  break;  
                case 1:
                setMyData("PREVIOUS");
                  break;          
                case 2:
                 setMyData("NEW");
                  break;        
                default:
                  //System.out.println("New Element");
              }
               display.setCurrent(form);
            }      
    }
   
    public void startApp() {
        display =  Display.getDisplay(this);
        form.append(dataEntry);
        form.addCommand(login);
        form.setCommandListener(this);
        display.setCurrent(form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }
   
    public void menu()
    {                                              
      String options[] = {" Next", " Previous", " New"};          

      // Create list using arrays, add commands, listen for events
      lsDocument = new List("Document Option:", List.IMPLICIT, options, null);
      lsDocument.setCommandListener(this);
      display.setCurrent(lsDocument);
    }
}
0
vandy02
Asked:
vandy02
1 Solution
 
CodeFishCommented:
You call getMyData() in the Constructor which sets its initial value. If you want that value to change you call setMyData() which you have done. But in order to display the change you need to call getMyData() again at some point after setting it.
So, if you change your first switch case as follows:

case 0:
                setMyData("NEXT");
                dataEntry.setString(getMyData());

The word "NEXT" will be displayed in the TextField of your main form.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now