Adding a RecyclerView

You want CrimeListFragment to display a list of crimes to the user. To do this you will use a RecyclerView.

The RecyclerView class lives in another Jetpack library. The first step to using a RecyclerView is to add the RecyclerView library as a dependency.

Listing 9.5  Adding RecyclerView dependency (app/build.gradle)

dependencies {
    ...
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    ...
}

Again, sync your Gradle files before moving on.

Your RecyclerView will live in CrimeListFragment’s layout file. First, you must create the layout file. Create a new layout resource file named fragment_crime_list. For the Root element, specify ...

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.