在 j2me 中为文本字段设置 onchange 侦听器

发布于 2024-12-11 16:22:46 字数 40 浏览 0 评论 0原文

是否可以在 j2me 中为文本字段设置 onchange 侦听器?

Is it possible to set a onchange listener to the textfield in j2me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2024-12-18 16:22:46

当然。使用 ItemStateListener< /a> 为此:

// below assumes that 'form' contains 'textField' which changes you want to listen to
form.setItemStateListener(new ItemStateListener() {
    public itemStateChanged(Item item) {
        if (item != textFiled) {
            return; // ignore other items
        }
        System.out.println("contents: [" + textField.getString() + "]");
    }
});

值得记住如何根据 API 文档调用 itemStateChanged 的详细信息:

...当用户...输入或修改文本字段中的值...

由设备决定何时考虑新值
已输入到一个项目中。例如,文本的实现
文本字段中的编辑因设备而异。

一般情况下,预计监听器不会在之后被调用
每一次改变都会发生。但是,如果某个项目的值已更改,
将调用侦听器来通知应用程序发生更改
在调用对另一个项目进行更改之前以及在执行命令之前
被传递到表单的 CommandListener。对于实现
有输入焦点的概念,监听器应该叫no
晚于焦点从其状态已改变的项目移开时
改变了。仅当项目的值具有时才应调用侦听器
实际上已经改变了。

如果应用程序更改了某个值,则不会调用侦听器
互动项目。

sure. Use ItemStateListener for that:

// below assumes that 'form' contains 'textField' which changes you want to listen to
form.setItemStateListener(new ItemStateListener() {
    public itemStateChanged(Item item) {
        if (item != textFiled) {
            return; // ignore other items
        }
        System.out.println("contents: [" + textField.getString() + "]");
    }
});

It is worth keeping in mind details of how itemStateChanged is invoked per the API docs:

...when the user ...enters or modifies the value in a TextField...

It is up to the device to decide when it considers a new value to have
been entered into an Item. For example, implementations of text
editing within a TextField vary greatly from device to device.

In general, it is not expected that the listener will be called after
every change is made. However, if an item's value has been changed,
the listener will be called to notify the application of the change
before it is called for a change on another item, and before a command
is delivered to the Form's CommandListener. For implementations that
have the concept of an input focus, the listener should be called no
later than when the focus moves away from an item whose state has been
changed. The listener should be called only if the item's value has
actually been changed.

The listener is not called if the application changes the value of an
interactive item.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文