Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialUnsubscribed User
5,729 PointsList items changing values
In my Hour Class i changed my getTemperature method to get me the temperature in Celsius instead of normal Fahrenheit like
public int getTemperature() {
mTemperature = (mTemperature - 32) * 5/9;
return (int) Math.round(mTemperature);
}
but now When I tested my app on emulator, the temperature in the hourly list gets displayed in Celsius but once i scroll through it the temperature randomly gets changed to -1 or -4 after scrolling and rechecking an hour from the list. Don't know what to do to fix it!
3 Answers
Unsubscribed User
5,729 Pointsnever mind! I figured it out :) I created a new private variable and set the value of Celsius temp to it and returned it instead of changing original mTemperature value.
Seth Kroger
56,414 PointsYou can get forecast.io to return Celsius temperatures instead of Fahrenheit by appending "?units=si" or "?units=auto" to the request URL. (made an error on first writing, the first char is a question mark, not and ampersand)
Unsubscribed User
5,729 PointsThanks Seth Kroger :) but could you please tell me the step by step procedure?
Seth Kroger
56,414 PointsWhen you put the URL for the API together:
private String forecastUrl = "https://api.forecast.io/forecast/YOUR_API_KEY_HERE/" +
latitude + "," + longitude + "?units=auto";
The forecast.io API accepts a number of options by adding them to the Url in query string format