Understanding Adapters

Adapters have several responsibilities, as we'll see, but generally speaking, they make binding data to a control easier and more flexible. Adapters in Android are employed for widgets that extend android.widget.AdapterView. Classes that extend AdapterView include ListView, GridView, Spinner, and Gallery (see Figure 4-20). AdapterView itself actually extends android. widget.ViewGroup, which means that ListView, GridView, and so on are container controls. In other words, they display a collection of child controls.

Figure 4-20. AdapterView class hierarchy

The purpose of an adapter is to provide the child views for the container. It takes the data and metadata about the view to construct each child view. Let's see how this works by examining the SimpleCursorAdapter.

0 0

Post a comment