0

I'm developing a simple weather applications using the yahoo API.

The method weatherInfo.getCurrentText() results in a string with the current weather condition in English.

For each weather condition there is an assigned code (list of condition + code here)

What I would like to do is to get the code with weatherInfo.getCurrentCode() and use a custom string. This will allow me to provide correct translations.

I'm trying to do this with string-array:

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

So, once I get the weather code is there any way I can assign the item on my string array?

mWeatherCode = get the code (assuming 10)

mText.setText(the item10 on my array list)

Chilledrat
  • 2,593
  • 3
  • 28
  • 38
iGio90
  • 3,251
  • 7
  • 30
  • 43

1 Answers1

3
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]);
}
Tobias
  • 7,723
  • 1
  • 27
  • 44
  • should i keep useing etc on my array list or can i just use etc... thanks for the solution meanwhile! – iGio90 Nov 25 '13 at 19:59
  • 1
    @iGui90 Just use `...`. The Yahoo API starts counting at 0 and the ADK does so, too. Well, you'll need to handle 3200 specifically. – Tobias Nov 25 '13 at 20:05