Join Albert Lo for an in-depth discussion in this video Implement GooglePhotosViewHolder, part of Android Development: Modern Android UI Design Elements.
- [Instructor] So, as previously mentioned, Android Studio is flagging an error here with the loadPhotos method, so let's go ahead and fix that. We'll select loadPhotos method and press Control + B. And we see that loadPhotos method has been declared private, so let's just make that public. Now, we switch back to AlbumViewHolders and looks like everything's clean. Now, we can go to AlbumGridAdapter and we will create our GooglePhotosViewHolder.
Let's uncomment this and now let's select GooglePhotosViewHolder and press on the light bulb. Select Create class. And, again, our class is going to be located in the viewHolders package, so we will add viewHolders here and select OK. GooglePhotosViewHolder will be similar to AlbumViewHolder. So, let's go into AlbumViewHolder and we will copy these two lines to inflate our views and initialize our image view.
And we will paste it into here. Let's also go to AlbumViewHolder and we will copy our private class members and paste it into here. Now, let's add our setData method. We press Control + O and select setData. Press OK. For our setData method, we are going to retrieve the photo entry for Picasa.
And we can do that by calling the getPhotoItem method for Google Photo's item. We will also add a local variable to hold our thumbnail. We can get our thumbnails string by calling photoEntry, getMediaGroup, getContents, get first element, getUrl.
Once we have our thumbnail, we can call Picasso to load our thumb into our image view. Now, let's go back to our constructor and we will add in a listener. Now, let's call the getRootView and call the setOnClickListener and we will pass in a reference to this GooglePhotosViewHolder.
Let's select the light bulb and we select Make GooglePhotosViewHolder implement the listener. Hit OK and now we have our listener. Now we are ready to look at the next view holder.
- Creating a custom layout with XML
- Setting up OnClick handlers
- Making API calls
- Creating custom views
- Implementing ViewHolder objects
- Signing certificates
- Adding a checkbox