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);
    }
}
vandy02Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.