ObjectChoicefield in blackberry

半城伤御伤魂 提交于 2019-12-25 01:32:32

问题


I have a objectchoice field with choices as say YES and NO. I want to handle event when the user selects any one of the choices.

for example when the user selects YES i want a labelField to be added to the screen. and when No is selected this label should be removed from the screen

Please help


回答1:


I think you can do it by implementing FieldChangeListener interface and override on fieldChanged event.




回答2:


In your window class, implement FieldChangeLIstener.

objectChoiceField.setChangeListener(this)

I would recommend doing marking the index of where you want to add/remove the label, so that in fieldChanged event you can more easily do what you want without risk of using an invalid index:

if (selectedIndex == 0) { // Yes
    if (!labelField.hasManager()) { 
        // If the field is not already present, add it to the screen. 
        insert(labelField, positionToInsertField); 
    } 
} else {  // No
    if (labelField.hasManager()) { 
        // Our field is currently on the screen - let's remove it now. 
        remove(labelField); 
    } 
}

You can find an example of very similar behavior in the code below:

http://svn.bbssh.org/trunk/BBSSH/src/org/bbssh/screens/ConnectionPropertiesScreen.java

Look for function "handleFontTypeChange", invoked from fieldChangeListener. In there, you'll see how based on the current selection (in this case truetype font vs bitmap font) we're adding and remove a control dynamically.



来源:https://stackoverflow.com/questions/3218206/objectchoicefield-in-blackberry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!