2
我正在Java ME中開發一個SMS應用程序。它可以選擇不同的運營商。如何在Popup ChoiceGroup中設置元素 - Java ME
我已經實現了RMS來存儲從POPUP ChoiceGroup中選擇的用戶名,密碼和運營商名稱。
我需要設置用戶在下次登錄時從rms中選擇的ChoiceGroup元素。
如何在RMS中選擇索引或字符串時如何執行此操作?
我正在Java ME中開發一個SMS應用程序。它可以選擇不同的運營商。如何在Popup ChoiceGroup中設置元素 - Java ME
我已經實現了RMS來存儲從POPUP ChoiceGroup中選擇的用戶名,密碼和運營商名稱。
我需要設置用戶在下次登錄時從rms中選擇的ChoiceGroup元素。
如何在RMS中選擇索引或字符串時如何執行此操作?
我需要設置ChoiceGroup的元素...
最直接的方式做到這一點是使用append
方法。在API documentation
myChoiceGroup.append(string1, null);
myChoiceGroup.append(string2, null);
// ... etc
查找詳細信息,這是很容易閱讀:
public int append(String stringPart,
Image imagePart)
Appends an element to the ChoiceGroup.
Specified by:
append in interface Choice
Parameters:
stringPart - the string part of the element to be added
imagePart - the image part of the element to be added,
or null if there is no image part
Returns:
the assigned index of the element
Throws:
NullPointerException - if stringPart is null
對於更復雜的應用,也有方法insert
和set
,在相同的鏈路上提供了這些API文檔以上。
爲了完整性注意,上述方法不僅在POPUP選擇組中可用,而且在實現接口的所有對象(包括其他類型的ChoiceGroup和List)中都具有類似的語義。
由於您還提到了工作RMS,請考慮查看another answer中提到的RMS教程。
@SabinJose對於這樣的轉換,我會使用[Integer.valueof(String)API](http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/ java/lang/Integer.html#valueOf(java.lang.String)「API javadocs」) – gnat 2012-07-06 13:17:11