字符串和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
答
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]);
}
感谢@Chilledrat进行编辑和我的英语不好对不起:) – iGio90