9
Displaying Lists with RecyclerView

CriminalIntent’s model layer currently consists of 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 9.1.

Figure 9.1  A list of crimes

A list of crimes

Figure 9.2 shows the overall plan for CriminalIntent in this chapter.

Figure 9.2  CriminalIntent with a list of crimes

CriminalIntent with a list of crimes

In the controller layer, you have a new ViewModel that will encapsulate the data for the new screen. CrimeListViewModel will store a list of Crime objects.

Displaying a list of crimes requires a new fragment in CriminalIntent’s controller layer: CrimeListFragment. MainActivity will host an instance of CrimeListFragment, which will in turn display the list of crimes on the screen.

(Where is CrimeFragment in Figure 9.2? It is part of the detail view, so we are not showing it here. In Chapter 12, you will connect the list and detail parts of CriminalIntent.)

In Figure 9.2, you can also see the view objects associated with MainActivity and CrimeListFragment. The activity’s view will consist of the same single fragment-containing FrameLayout. The fragment’s view will consist of a RecyclerView. You will learn more about the RecyclerView class later in the chapter.

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

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