雅虎天气API的字符串和int比较



我正在使用yahoo API开发一个简单的天气应用程序。

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

对于每个天气条件,都有一个指定的代码(此处为条件列表+代码)

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

我正在尝试使用字符串数组:

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

那么,一旦我得到天气代码,有什么方法可以在字符串数组中分配项目吗?

mWeatherCode=获取代码(假设10)

mText.setText(我的数组列表中的项10)

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

最新更新