English subtitles

← Update the Adapter - Developing Android Apps

Get Embed Code
9 Languages

Showing Revision 14 created 05/25/2016 by Udacity Robot.

  1. From the logs, we know that we have the right forecast
  2. data and it's in the right format that we want as
  3. an array of strings. So it's finally time to update the
  4. UI. Think back on how AsyncTasks are able to pass data
  5. back onto the main thread. You can hit Ctrl+O to see
  6. the list of available methods we can override in AsyncTask. If
  7. you click on any of them, it will be prepopulated in
  8. the code for you. Then, you can update ArrayAdapter with the new
  9. data that was retrieved by the AsyncTask. As a hint, you
  10. can make the ForecastAdapter be a global variable. That way, you
  11. can access it from within the FetchWeatherTask. Make sure that this
  12. is not a static class, otherwise, you won't be able to
  13. access the member variable from the forecast fragment. Then, go ahead
  14. and compile and build the app. When you run it, and
  15. you hit the refresh button, you should see a week's worth
  16. of weather data for your location. Once it's working, you can
  17. remove the verbose log statements so you don't
  18. clutter the logs. As you're working on this
  19. code, if you see an unsupported operation exception,
  20. make sure that when you're creating the fake
  21. data, that when you initialize ArrayAdapter, you passed
  22. in a list of strings, and not an
  23. array. That way you can call the clear
  24. method or the add method on this list collection.