Search code examples
java-memidpmidletlcdui

One itemStateChanged method for many Displayable objects in j2me


Can I have one itemStateChanged method to monitor changes triggered by user for many Displayable objects in a MIDlet (e.g. for a form and a list), using if clauses to decide what was changed, or do I have to create a different method for each Displayable I want to monitor?


Solution

  • If you are talking about instantiating several Form and one ItemStateListener and calling Form.setItemStateListener() several times with the same parameter, then yes, you can do that.

    Theoretically, you should write thread-safe code in your implementation of itemStateChanged but given the way existing java-me implementations handle events and the very small number of MIDP-compliant phones using 2 physical screens, I don't think it's very important in practice.