Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Weather App Working with JSON Setting the Weather Icon

Sharina V Jones
Sharina V Jones
1,795 Points

AccuWeather Icons

I just wanted to share the code I had using the AccuWeather API. It sends the info as an int, rather than a string.

My declarations

public class CurrentWeather {
    ...
    private int weatherIcon;
    ...

    public int getIconId(int weatherIcon) {
        //https://developer.accuweather.com/weather-icons
        //1. clear-day, 33. clear-night, 18. rain, 22. snow, 25. sleet, 32. windy, 11. fog, 7. cloudy
            //3. partly-cloudy day, 39. partly-cloudy-night

        int iconId = R.drawable.clear_day;

        switch(weatherIcon) {
            case 1:
                iconId = R.drawable.clear_day;
                break;
            case 33:
                iconId = R.drawable.clear_night;
                break;
            case 18:
                iconId = R.drawable.rain;
                break;
            case 22:
                iconId = R.drawable.snow;
                break;
            case 25:
                iconId = R.drawable.sleet;
                break;
            case 32:
                iconId = R.drawable.wind;
                break;
            case 11:
                iconId = R.drawable.fog;
                break;
            case 7:
                iconId = R.drawable.cloudy;
                break;
            case 3:
                iconId = R.drawable.partly_cloudy;
                break;
            case 39:
                iconId = R.drawable.cloudy_night;
                break;
        }
        return iconId;
    }
...
}