You Are Here:

Community: Wiki

This page was last modified on 25 September 2009, at 09:20.

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

From Forum Nokia Wiki

Reviewer Approved   

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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia