Define and implement the ViewHolder class for the header view.
- Now let's switch back to our AlbumGridAdapter. The final ViewHolder that we will build is HeaderVeiwHolder. So let's uncomment this line. Let's select "HeaderViewHolder" and look for the lightbulb and create a new class and again it will be under the ViewHolders package. Select that. So our HeaderViewHolder will also inflate a layout similar to the other ViewHolders.
So let's go to "AlbumViewHolder". And let's select this first line for inflating the layout. Copy that with "Command + C". Go back into our HeaderViewHolder and paste that in here. Now instead of inflating a "google_photos_item", let's select that and replace it with a new layout called "google_photos_header". Now let's select the lightbulb and create a new layout resource file.
And clean this up a bit again by putting everything in their own line. In our HeaderLayoutResource we will define a TextView. The TextView will be width "match_parent". And the height "wrap_content". We will also add an ID and we will give the ID a name of "label". We're also going to add a TextSize here. 16 point font. And we will give a default text.
So the default text will be called "Header" and we will create a string resource for this. So select "Extract string resource" and select "OK". Now we have our google_photos_header layout. Let's switch back to HeaderViewHolder and we will press "Control + O" to add our setData method. In our setData method, just like our other ViewHolders, we are going to bind our data to our view. For the case of HeaderViewHolder our view will be a TextView.
So let's go and define a private class number for our TextView and we go back into our setData method and we're going to call the setTextmethod for our TextView. The text will be a TimeStamp. Now for our HeaderView if you want to get fancy you could add in image view and text view but for the purposes of our course we're going to keep our HeaderView simple and we'll just use TimeStamp for our HeaderView.
TimeStamp we can retrieve from calling the getTimestamp method of our google_photos_item. Now we have finished implementing the code for HeaderViewHolder.
- Creating a custom layout with XML
- Setting up OnClick handlers
- Making API calls
- Creating custom views
- Implementing ViewHolder objects
- Signing certificates
- Adding a checkbox