10
Displaying Lists with RecyclerView

Currently, CriminalIntent can only display information about a single instance of Crime. In this chapter, you will update CriminalIntent to work with a list of crimes. The list will display each Crime’s title and date, as shown in Figure 10.1.

Figure 10.1  A list of crimes

A list of crimes

Many aspects of the work you will complete in this chapter will feel familiar from the work you did in previous chapters. For example, much like you did in GeoQuiz, you will create a new ViewModel to encapsulate the data for the new screen. CrimeListViewModel will store a list of Crime objects.

Since this data will be displayed on a new screen, you will also create a new fragment, called CrimeListFragment. Your MainActivity will host an instance of CrimeListFragment, which in turn will display the list of crimes on the screen.

The activity’s view will still consist of a single FragmentContainerView. The fragment’s view will consist of a RecyclerView, a class that allows you to efficiently recycle views.

For now, the list and detail parts of CriminalIntent will lead separate lives. In Chapter 13, you will connect them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset