Join Albert Lo for an in-depth discussion in this video The Custom RecyclerView structure, part of Android Development: Modern Android UI Design Elements.
- [Instructor] Here is a preview of what we want to build. We want to show a grid of albums and photos. We also want to add a section header to our grid. So that we can identify what type of photos we are viewing. To support mixed photo and header views our recycler view will need to define multiple view types. That will be processed during the onbind view holder stage. The main components of our solution include some of the typical elements in a recycler view.
So let's take a look at a diagram which illustrates how it all fits together. With the exception of the data source each box here represents a component that we will build. So let's briefly review them here. The first one is the grid recycler view. This is a sub-class of recycler view customized for displaying grids. The next one is data source. This is typically a collection of data for displaying our views. In our app, the data source will come from the google photos library.
Next is the recycler view adapter. For our app this will be called album grid adapter. And its job is to translate data into a format that can be used by the views. Next is our view holders. We will have three view holders for this course. The first one is header view holder. And it is responsible for displaying header information. The next one is album view holder. And we also have one for google photos view holder.
And those will be responsible for displaying the albums and photos. We will also be adding a couple of new components. The first one is the base grid adapter. This will be an abstract base class that will be common to both the photos and to the albums. The next one is google photos manager. And this is part of the model and it will be focused on managing the backing data. And finally we have the google photos items. This is the other part of our model and it's a pure java class which will contain the data needed for the view holders to display the view.
Again, we are going to implement all of these components in this diagram. But for now let's take a closer look at the grid recycler view.
- Creating a custom layout with XML
- Setting up OnClick handlers
- Making API calls
- Creating custom views
- Implementing ViewHolder objects
- Signing certificates
- Adding a checkbox