Customizing List Items

So far, each of your list items only displays the title of a Crime – the result of Crime.toString().

When you want to display more than just a string, you can create custom list items. Implementing custom list items requires two things:

  • creating a new layout in XML that defines the view for the list item

  • creating a subclass of ArrayAdapter<T> that knows how to create, populate, and return the view defined in the new layout

Creating the list item layout

For CriminalIntent, a list item’s layout should include the crime’s title, its date, and whether the case has been solved (Figure 9.11). This layout calls for two TextViews and a CheckBox.

Figure 9.11  A handful of custom list items

You create a new layout for a list item ...

Get Android Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

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