I am making a weather app. Whole app is done and everything is working fine except NIGHT ICONS. I have set icons for the day. But I don't how to set two different icons on one condition that checks the time, if its day it shows SUN & if its night it should show MOON
Here is my code:
private static String updateWeatherIcon(int condition) {
if (condition >= 0 && condition < 300) {
return "tstorm1";
} else if (condition >= 300 && condition < 500) {
return "light_rain";
} else if (condition >= 500 && condition < 600) {
return "shower3";
} else if (condition >= 600 && condition <= 700) {
return "snow4";
} else if (condition >= 701 && condition <= 771) {
return "fog";
} else if (condition >= 772 && condition < 800) {
return "tstorm3";
} else if (condition == 800) {
return "sunny";
} else if (condition >= 801 && condition <= 804) {
return "cloudy2";
} else if (condition >= 900 && condition <= 902) {
return "tstorm3";
} else if (condition == 903) {
return "snow5";
} else if (condition == 904) {
return "sunny";
} else if (condition >= 905 && condition <= 1000) {
return "tstorm3";
}
return "dunno";
}
please help me out.
1) The weather API would never return "sunny" on the night time. So, you may not need to worry about it.
2) OpenWeather API returns the icon code in the response - "icon":"04n" They have a set of weather icons listed in https://openweathermap.org/weather-conditions which you can use or mimic. They do have different icons for day and night.
Hope that helps!