1

我正在创建一个包含两个 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");
        }
    }
}
4

2 回答 2

3

您是否尝试过覆盖 的navigationClick方法ObjectChoiceField

这是一个例子:

ObjectChoiceField selectionField = new ObjectChoiceField("Select the Country",countryArray)
{
    protected boolean navigationClick(int arg0, int arg1) 
    {
        return super.navigationClick(arg0, arg1);
    }
};
于 2011-12-02T09:20:25.263 回答
-2

cf 是 ChoiceField。使用 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;
                }
            }
        });
于 2011-11-30T13:02:45.227 回答