Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

5. Adapters, ListViews, and Lists > Two Pieces to Each List

Two Pieces to Each List

To display lists of ordered data with Android, there are two major components you’ll need to deal with.

ListView

First, you’ll need a ListView in which to display your content. This is the view whose job it is to display the information. It can be added to any screen layout, or you can use Android’s ListActivity or ListFragment to handle some of the organization for you. If your screen is primarily designed to show a collection of data to the user in list form, I highly suggest you use ListActivity and its cousin ListFragment.

Adapter

The second major class you’ll need to deal with is the Adapter. This is the object that will feed the individual views, a little bit at a time, to the ListView. It’s also responsible for filling and configuring the individual rows to be populated in the ListView. There are as many Adapter subclasses as drops of water in the ocean (all right, perhaps slightly fewer), and they cover the range of data types—from static string lists (ArrayAdapters) to the more dynamic lists (CursorAdapters). You can extend your own adapter (which I’ll show you in the second half of this chapter). For now, let me show you how to create a simple main menu with a ListView.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial