This repository contains the source code for the CrimeLister Android application. The app has been enhanced from the initial example used in class (example #10) to showcase advanced features of the RecyclerView
. The application now supports two types of rows in the RecyclerView
: a normal row and a row for more serious crimes.
- Two Types of Rows: The application utilizes the
RecyclerView.Adapter
's view type feature to differentiate between normal crimes and more serious crimes that require police intervention. - Dynamic Row Generation: Based on the
requiresPolice
property of theCrime
object, theRecyclerView
dynamically decides which type of view should be loaded. - Enhanced Crime Object: A new boolean property,
requiresPolice
, has been added to theCrime
model to support this feature. - Custom View Logic: Within the
CrimeListAdapter
, thegetItemViewType(Int)
function has been implemented to return different view types based on the crime's seriousness. - Adaptive View Holders: The
onCreateViewHolder(ViewGroup, Int)
function has been updated to inflate different layouts depending on theviewType
. A new layout with a "call police" button is used for more serious crimes.
getItemViewType(Int)
: This function checks therequiresPolice
property of eachCrime
object and returns an integer representing the view type (normal or serious).onCreateViewHolder(ViewGroup, Int)
: Based on the viewType, this function inflates either the normal row layout or the layout for serious crimes. Each layout corresponds to a differentViewHolder
.requiresPolice
Property: Added to theCrime
class, this boolean value determines the type of crime and subsequently, the type of row used in the list.
To use this application:
- Clone the repository to your local machine.
- Open the project in Android Studio.
- Run the application on your device or emulator.
We welcome contributions to improve this application further:
- Fork the project to your GitHub account.
- Create a new branch for your feature (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a pull request.
Thank you for your interest in contributing to the CrimeLister app!
This project is licensed under the MIT License - see the LICENSE file for details.