Tuesday, December 25, 2012

Android beginner tutorial: Part 31 - Displaying data using AdapterView widgets

Today we'll learn the mechanics behind displaying text data in list widgets.

There are multiple list type widgets in Android. The most common ones are ListView, GridView, and Spinner (Gallery and SlidingDrawer classes once were a part of this list, but now they are deprecated). They are all subclasses of AdapterView class, which is a view whose children are determined by an Adapter.

If you read my previous tutorials, you already know that an Adapter is a bridge between a data provider and the widget that displays the data. It provides access to each element of the data and also takes care of displaying each item in the data by creating View objects.

All the AdapterView subclasses are containers that displays the given data in a specific way and handles all the user interaction events with each of the children, that are generated from the data.

There are multiple variations of the Adapter class for specific uses. For example, we already know about the ArrayAdapter - it lets us use the data from an array to display it in a widget (in the previous tutorials, we displayed it in AutoCompleteTextView and MultiAutoCompleteTextView objects).

Another common adapter is CursorAdapter, which is used for reading and displaying data from Cursor objects. A Cursor is an interface that provides read-write access to the resulted data returned from a database query.

It is possible to create your own custom Adapter classes for more specific needs. It is also possible to create your own AdapterView classes, which display the provided data.

The AdapterView class is the base class for AbsListView and AbsSpinner classes. The AbsListView class can be extended to display data in a list-type way - it is used in ListView and GridView components. The AbsSpinner class is used for dropdown lists in Spinner widget.

That's the basic idea behind displaying provided data in list widgets.

We are now able to start learning separate list widgets in detail.

Thanks for reading!

No comments:

Post a Comment