ObjectChoice 字段的侦听器

发布于 2024-12-18 15:56:00 字数 1067 浏览 3 评论 0原文

我正在创建一个包含两个 ObjectChoiceFields 的 BlackBerry 应用程序。我想为每个人添加听众。我搜索过但没有找到任何有用的代码。

它就像网站上的国家/地区选择器。我正在寻找简单的逻辑,并且不需要任何面向数据库的解决方案。谁能描述如何为这两个 ObjectChoiceField 添加侦听器?

我在下面附上了我的代码,但它仅适用于国家/地区选择字段。当我改变状态选择时什么也没有发生。

public class MyApplication extends MainScreen implements FieldChangeListener
{
ObjectChouceField choice_c,choice_s;
public MyApplication ()
    {
        this.setTitle("hai");
choice_c = new MyChoiceField("Select a Country", countryArray);
        choice_c.setChangeListener(this);
        this.add(choice_c);
choice_s = new MyChoiceField("Select a State", stateArray);
        choice_s.setChangeListener(this);
        this.add(choice_s);
                ..................
                ..................
}
public void fieldChanged(Field field, int context) 
    {
        if(field == choice_category)
        {
            Dialog.alert("choice country has been pressed");
        }
        else if(field == choice_round)
        {
            Dialog.alert("choice state has been pressed");
        }
    }
}

I am creating a BlackBerry application which contains two ObjectChoiceFields. I want to add listeners for each of them. I searched for that but did not find any of useful code.

It is like a country-state selector on websites. I am looking for simple logic, and I have no need of any database oriented solution. Can anyone describe how to add listeners for those two ObjectChoiceField?

I have have attached my code below, but it is only working for country choice field. Nothing happens when I change state choice.

public class MyApplication extends MainScreen implements FieldChangeListener
{
ObjectChouceField choice_c,choice_s;
public MyApplication ()
    {
        this.setTitle("hai");
choice_c = new MyChoiceField("Select a Country", countryArray);
        choice_c.setChangeListener(this);
        this.add(choice_c);
choice_s = new MyChoiceField("Select a State", stateArray);
        choice_s.setChangeListener(this);
        this.add(choice_s);
                ..................
                ..................
}
public void fieldChanged(Field field, int context) 
    {
        if(field == choice_category)
        {
            Dialog.alert("choice country has been pressed");
        }
        else if(field == choice_round)
        {
            Dialog.alert("choice state has been pressed");
        }
    }
}

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

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

发布评论

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

评论(2

衣神在巴黎 2024-12-25 15:56:00

您是否尝试过重写ObjectChoiceFieldnavigationClick 方法?

这是一个例子:

ObjectChoiceField selectionField = new ObjectChoiceField("Select the Country",countryArray)
{
    protected boolean navigationClick(int arg0, int arg1) 
    {
        return super.navigationClick(arg0, arg1);
    }
};

Have you tried overriding the navigationClick method of the ObjectChoiceField?

Here is an example:

ObjectChoiceField selectionField = new ObjectChoiceField("Select the Country",countryArray)
{
    protected boolean navigationClick(int arg0, int arg1) 
    {
        return super.navigationClick(arg0, arg1);
    }
};
趁微风不噪 2024-12-25 15:56:00

cf 是选择字段。使用 getSelectedIndex 来相应地触发事件。


cf.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
                switch (cf.getSelectedIndex()) {
                case 0:
                    //code here //
                    break;
                default:
                    break;
                }
            }
        });

cf is the ChoiceField. Use the getSelectedIndex to and trigger events accordingly.


cf.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
                switch (cf.getSelectedIndex()) {
                case 0:
                    //code here //
                    break;
                default:
                    break;
                }
            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文