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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.