字符串和INT comparsion雅虎天气API

问题描述:

我正在开发使用雅虎API一个简单的天气应用程序。字符串和INT comparsion雅虎天气API

方法weatherInfo.getCurrentText()产生一个包含英文当前天气条件的字符串。

针对每种天气条件有一个分配的代码(list of condition + code here

我想这样做是weatherInfo.getCurrentCode()获取代码,并使用自定义字符串。这将使我能够提供正确的翻译。

我试图用字符串数组来做到这一点:

<string-array name="weather_conditions"> 
    <item0>Sunny</item0> 
    <item1>Cloudy</item1> 
    etc... 
</string-array> 

所以,一旦我得到的天气代码有什么办法,我可以我的字符串数组上指派的项目?

mWeatherCode =获取代码(假设10)

mText.setText

+0

感谢@Chilledrat进行编辑和我的英语不好对不起:) – iGio90

String[] conditions = getResources().getStringArray(R.array.weather_conditions); 
if(mWeatherCode < 0 || mWeatherCode > conditions.length) { 
    mText.setText(R.string.err_invalid_condition); 
} else { 
    mText.setText(conditions[mWeatherCode]); 
} 
+0

(在我的数组列表上item10)我应该保持期运用等我的数组列表或可我只是使用等...感谢同时解决! – iGio90

+1

@ iGui90只需使用' ...'。雅虎API从0开始计数,ADK也这样做。那么,你需要专门处理3200。 –

+0

标记为正确...测试和工作。谢了哥们! – iGio90