我目前正在研究微調框中的月轉換。 這裏我試圖從系統中檢索currentmonth(「10」)並將月的值傳遞給枚舉以獲得相應的枚舉名稱(「Oct」)。獲取微調框中的枚舉名稱
我有微調數組字符串從1月至12月開始。 當我試圖獲取位置的微調框中的枚舉名稱「十月」,它返回空白。但是,當我嘗試在getPosition中「十月」硬編碼時,它工作。我無法找出爲什麼getEnumByString返回空白。誰能幫我。
String tempMonth=String.valueOf(monthCurrent);
monthSpin.setSelection(adapterMonth.getPosition(MonthConversion.getEnumByString(tempMonth));
MonthConversion:
public enum MonthConversion {
Jan("1"), Feb("2"), Mar("3"), Apr("4"),May("5"),Jun("6"),Jul("7"),Aug("8"),Sep("9"),Oct("10"),Nov("11"),Dec("12");
private String mValue;
private MonthConversion(String s) {
mValue = s;
}
public String getStatusCode() {
return mValue;
}
public static String getEnumByString(String code){
for(MonthConversion e : MonthConversion.values()){
if(code == e.mValue)
return e.name();
}
return null;
}
}
發佈您的MonthConversion。 –