Question: Requirements: For this first assignment, you will create two types of rows in your RecyclerView: a normal row and a row for more serious crimes.
Requirements:
For this first assignment, you will create two types of rows in your RecyclerView: a normal row and a row for more serious crimes. To do so, you'll need to use the view type feature built into RecyclerView.Adapter.
1. Add a new property,
mRequiresPolice to the Crime object and use it to decide which view to load on the CrimeAdapter.
To do so, you'll need to use the getItemViewType(int) method.
You can read more about the method here, and you can read more about how to implement a List with RecyclerView here.
2. Add logic that returns a different ViewHolder based on the viewType value returned by getItemViewType(int) in the onCreateViewHolder method.
Use the original layout for crimes that do not require police intervention. Add a new layout adding a button that says "Call Police" for crimes that do.
The button should cause a Toast to pop up with the message "Police Are On Their Way!". Initialize the crimes list with some crimes that need the police (and some that don't) to demonstrate the new functionality.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
