Lists are very useful tools and have become ubiquitous in mobile computing. So much so that my daughter asked, after seeing my brother-in-law with a cast needed because of carpal tunnel syndrome from computer use, if she was going to get a similar disease because she does this so often. With that she moved her index finger in the list swipe gesture.
Lists are so common because they are a very useful way to organize, display, and access large amounts of data on a very small screen. This chapter explores the implementation of lists in Android. It covers simple lists that exploit the built-in list capabilities of the Android SDK and then examines the development of more complex lists, tailored specifically to the task at hand.
Finally, the chapter concludes by introducing passing data between activities, using user preferences to sort a list, and changing the app’s launch activity to complete the Contact List Activity. Lists and Adapters Two components are required for any list implementation in Android: a List View widget and an adapter.
The List View widget is an object that can display a vertical list of items that can be scrolled through. An Adapter is dynamically associated with the List View. The adapter provides access to the underlying data source for the list. In the case of a simple list, after an adapter is associated with the widget, insertion of data as a list item is handled automatically.
In the case of a complex list, the developer must create a subclass of an Adapter object and code the display and behavior of the list in the new subclass. Lists an Adapter View is the super class of all views that are bound to an underlying data source. A View is the base class for all user interface components, such as the widgets used in creating layouts.
The visible component of a list is implemented with a list View widget in an XML layout file. The widget has attributes that allow the user to configure some aspects of the display. In many ways, a list View is a standard widget. However, if given the special ID of @id/android: list and a special subclass of Activity, many of the tasks of list implementation are easier because the developer can take advantage of many built-in features of the SDK.
To take advantage of these features, the Activity associated with the layout containing the list View must be a subclass of list Activity rather than Activity. You don’t have to use the List Activity subclass, but that requires more coding, so only the list activity approach is used in this chapter.