×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    16

    notifyStateChanged method??

    i gone through docs, but i didnt understand whats the use of notifyStateChanged method.....any examples plz....

    Thanks......

  2. #2
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: notifyStateChanged method??


  3. #3
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: notifyStateChanged method??

    The notifyStateChanged method is used to trigger an action when the state of an item has changed (like if the text in a TextField is modified or if the value of a Gauge is modified etc.). The midlet that uses it has to implement the ItemStateListener interface.

    Here's an example:
    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class MyMidlet extends MIDlet implements CommandListener, ItemStateListener {
        
        public Form form=new Form("");
        public Command exit=new Command("Exit", Command.EXIT, 1);
        public Display display=Display.getDisplay(this);
        public TextField tf=new TextField("Bla", "", 100, TextField.LAYOUT_LEFT);
        
        public void startApp() {
            //Tell the application to listen for changes of the state of the objects in the form
            form.setItemStateListener(this);
            form.append(tf);
            form.addCommand(exit);
            form.setCommandListener(this);
            display.setCurrent(form);
        }
     
        public void pauseApp() {
        }
     
        public void destroyApp(boolean unconditional) {
        }
     
        public void commandAction(Command c, Displayable d) {
            if(c==exit)
                notifyDestroyed();
        }
        
        //This method is called when a state change occurs
        public void itemStateChanged(Item i) {
            if(i==tf)
                form.append("Text was changed");
        }
        
    }

Similar Threads

  1. What is happening in InputStream.Skip method?
    By orsteglasy in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2007-03-02, 19:34
  2. Is switching to another Canvas inside a paint() method OK?
    By falconpl in forum Mobile Java General
    Replies: 2
    Last Post: 2006-05-06, 00:15
  3. Replies: 0
    Last Post: 2004-03-03, 10:34
  4. Methods, that take lots of space
    By doctordwarf in forum Mobile Java General
    Replies: 4
    Last Post: 2003-07-30, 11:05

Posting Permissions

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