Challenge: RecyclerView ViewTypes

For this advanced challenge, you will create two types of rows in your RecyclerView: a normal row and a row for more serious crimes. To implement this, you will work with the view type feature available in RecyclerView.Adapter. Add a new property, requiresPolice, to the Crime object and use it to determine which view to load on the CrimeAdapter by implementing the getItemViewType(Int) function (developer.android.com/​reference/​android/​support/​v7/​widget/​RecyclerView.Adapter.html#getItemViewType).

In the onCreateViewHolder(ViewGroup, Int) function, you will also need to add logic that returns a different ViewHolder based on the new viewType value returned by getItemViewType(Int). Use the original ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.