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 trial

Android Android Lists and Adapters (2015) Lists with RecyclerViews Using a Layout Manager

List 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

never 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
Seth Kroger
56,413 Points

You 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)

Thanks Seth Kroger :) but could you please tell me the step by step procedure?

Seth Kroger
Seth Kroger
56,413 Points

When 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