Part 1 - ListView Parts and Functionality
- PDF for offline use
Let us know how you feel about this
last updated: 2017-06
ListView consists of the following parts:
Rows – The visible representation of the data in the list.
Adapter – A non-visual class that binds the data source to the list view.
Fast Scrolling – A handle that lets the user scroll the length of the list.
Section Index – A user interface element that floats over the scrolling rows to indicate where in the list the current rows are located.
These screenshots use a basic
ListView control to
show how Fast Scrolling and Section Index are rendered:
The elements that make up a
ListView are described in
more detail below:
Each row has its own
View. The view can be either one of the built-in
views defined in
Android.Resources, or a custom view. Each row can
use the same view layout or they can all be different. There are
examples in this document of using built-in layouts and others
explaining how to define custom layouts.
ListView control requires an
Adapter to supply the formatted
View for each row. Android has built-in Adapters and Views that can
be used, or custom classes can be created.
ListView contains many rows of data fast-scrolling can be
enabled to help the user navigate to any part of the list. The
fast-scrolling 'scroll bar' can be optionally enabled (and customized
in API level 11 and higher).
While scrolling through long lists, the optional section index provides the user with feedback on what part of the list they are currently viewing. It is only appropriate on long lists, typically in conjunction with fast scrolling.
The primary classes used to display
ListViews are shown here:
The purpose of each class is described below:
ListView – user interface element that displays a scrollable collection of rows. On phones it usually uses up the entire screen (in which case, the
ListActivityclass can be used) or it could be part of a larger layout on phones or tablet devices.
View – a View in Android can be any user interface element, but in the context of a
ListViewit requires a
Viewto be supplied for each row.
BaseAdapter – Base class for Adapter implementations to bind a
ListViewto a data source.
ArrayAdapter – Built-in Adapter class that binds an array of strings to a
ListViewfor display. The generic
ArrayAdapter<T>does the same for other types.
CursorAdapter – Use
SimpleCursorAdapterto display data based on an SQLite query.
This document contains simple examples that use an
well as more complex examples that require custom implementations of