ObjectChoice 字段的侦听器
我正在创建一个包含两个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过重写
ObjectChoiceField
的navigationClick
方法?这是一个例子:
Have you tried overriding the
navigationClick
method of theObjectChoiceField
?Here is an example:
cf 是选择字段。使用 getSelectedIndex 来相应地触发事件。
cf is the ChoiceField. Use the getSelectedIndex to and trigger events accordingly.