Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Challenge: RecyclerView View Types
For this advanced challenge, create two types of rows in your RecyclerView: a normal row and a row for more serious crimes. To implement this, you will need to 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 CrimeListAdapter by implementing the getItemViewType(Int) function (developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#getItemViewType(int)).
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access