Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How can I find out when the value in the TextField has been changed?

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: arunjyothiskp (21 Nov 2007)
Last edited: hamishwillee (09 Aug 2013)


When working with TextField items, it is often useful to be automatically notified when the TextField content changes (e.g.: to implement an autocomplete field, or some sort of automated filter for a list of other Items).

Source code

You must use the ItemStateListener interface and register the listener to the form. The easiest way is to implement ItemStateListener on the form that contains your TextField and put your code into the itemStateChanged method.

   class MyClass extends Form implements ItemStateListener
{
public MyClass()
{
setItemStateListener(this);
}
 
public void itemStateChanged(Item item)
{
...
}
}

Another approach would be to create an anonymous class and register it with the form:

   public class MyClass extends MIDlet 
{
public void startApp()
{
Form form = new Form("My Test");
// an anonymous class
ItemStateListener listener = new ItemStateListener()
{
public void itemStateChanged(Item item)
{
// do something
}
};
 
// register for events
form.setItemStateListener(listener);
...
display.setCurrent(form);
}
}

Download

You can download a MIDlet showing the code presented in this article here: Media:TextFieldItemStateListenerMIDlet.zip

Related resources

This page was last modified on 9 August 2013, at 06:33.
21 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×