代号一-选择器的addActionListener [英] Codename One - addActionListener of a Picker

查看:56
本文介绍了代号一-选择器的addActionListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码(在许多版本的Android和iOS中)显示了取消和确定选项。我希望仅当用户点击确定按钮时才执行addActionListener代码。目前,即使用户点击取消按钮,该代码也会执行:

The following code, in a lot of version of Android and iOS, shows the options "Cancel" and "OK". I would like that the addActionListener code is executed only when the user taps on the "OK" button. At the moment, that code is executed even if the user taps the "Cancel" button:

    Form hi = new Form("Hi World", BoxLayout.y());
    Picker languagePicker = new Picker();
    languagePicker.setType(Display.PICKER_TYPE_STRINGS);
    languagePicker.setStrings("Italian", "English", "German");
    languagePicker.setSelectedString("English");
    languagePicker.addActionListener((ev) -> {
        String newLanguage = languagePicker.getSelectedString();
        if (newLanguage != null && newLanguage.length() > 0) {
            Log.p("Language selected: " + newLanguage);
        }
    });
    hi.add(languagePicker);
    hi.show();


推荐答案

Picker 是本机组件。因此,在使用它时,我们只是没有访问或一致性级别。请记住,在某些形式下它甚至没有元素列表,因此我们的控制非常有限。

The Picker is a native component. As a result we just don't have that level of access or consistency when working with it. Keep in mind that in some forms it won't even have a list of elements so our control is very limited.

这篇关于代号一-选择器的addActionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆