Sunlight 2.01 to 2.09 – Update adapter

Almost nothing new for Android L and Material Design with regard to chapter 2 “Connect Sunshine to the Cloud” of the Udacity course. But since we used a RecyclerView instead of the ListView, there is one minor difference.

[*Caution: Outdated content. My sunlight project has been discontinued. It refers to earlier versions of the v7 appcompat Library (21.0.3) and Android Studio (1.1).  I’ll keep the posts online for reference but with the current version of appcompat Library things may be different / easier today, so please refer to more up-to-date sources.]

This article is part of the Sunlight project and refers to Lesson 2 of Googles Udacity Course “Developing Android Apps”.

Update the Adapter

The difference is in the last step, where the adapter data is updated. We already changed the mWeekForcast List into a member variable of the ForecastFragment. Now we have to do so also for the ForecastAdapter.

Instantiation in onCreateView:

Tell him!

In contrast to  the Array Adapter, which auto-updates the view when data is updated (as this video explains), the RecyclerView Adapter has to be told via the notifyDataSetChanged() method.

And that’s it for Lesson 2.

You may want to compare the ForecastFragment code from Udacity to the Sunlight version.

I promise, there will be more of the “fancy new L stuff ” we’re looking for in Lesson 3…

Leave a Reply

Your email address will not be published. Required fields are marked *