2010-07-10 67 views
0

我有一個選項,如YES和NO。 我想在用戶選擇任何一個選項時處理事件。Blackberry中的ObjectChoicefield

例如,當用戶選擇「是」時,我希望labelField被添加到屏幕上。 並沒有選擇時,這個標籤應該從屏幕

被刪除,請幫忙

+0

請記住接受您認爲有用的答案;並在需要更多信息的地方提供評論。如果你不這麼做,人們會停止試圖回答你的問題。 – 2010-07-13 16:18:12

回答

0

我想你可以通過實現FieldChangeListener接口做到這一點,並覆蓋上fieldChanged事件。

0

在你的窗口類中,實現FieldChangeLIstener。

objectChoiceField.setChangeListener(this) 

我建議做標記,你要添加的索引/移除標籤,以便在fieldChanged事件中,你可以更容易地做你想做的,而不使用無效指數的風險:

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); 
    } 
} 

您可以在下面的代碼非常相似行爲的一個例子:

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

查找功能「handleFontTypeCh ange「,從fieldChangeListener調用。在那裏,你會看到如何基於當前的選擇(在這種情況下truetype字體與位圖字體),我們正在動態添加和刪除控件。