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

Posted on 2008-11-18
Last Modified: 2013-11-24
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:


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();
        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"))
            else if (c == List.SELECT_COMMAND)
              switch (lsDocument.getSelectedIndex())
                case 0:
                case 1:
                case 2:
                  //System.out.println("New Element");
    public void startApp() {
        display =  Display.getDisplay(this);

    public void pauseApp() {

    public void destroyApp(boolean unconditional) {
    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);
Question by:vandy02
    1 Comment
    LVL 6

    Accepted Solution

    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:

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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now