In Android development, the ListView is a relatively common development component that presents specific content in a list and is adaptive to the length of the data.
- The display of a list requires three elements:
- ListView: A view used to display a list;
- Adapter: An intermediary used to map data to a ListView, an adapter class that uses the adapter pattern in design mode, which is a bridge between the view and the data, providing access to the data, generating a view of each list item,
Common adapter classes are: Arrayadapter, Simpleadapter, and Simplecursoradapter.
Data: Mapped strings, images, or basic components;
- Common Properties of the ListView:
| Properties |
Description |
| Android:divider |
Sub-dividing line |
| Android:drivideheight |
Split Line Height |
| Android:listselector |
Sub-item Click Effect |
| Android:scrollbars |
Slide Bar |
- Common Methods for ListView:
| Method |
Description |
| Addfooterview (View v) |
Add a view to the tail of the list |
| Addheaderview (View v) |
Add a view to the list header |
| Setadapter (ListAdapter Adapyer) |
Setting up the adapter |
| Setdivider (drawable divider) |
Set the subkey separator bar |
| Setdividerheight (int Height) |
Set the height of the divider bar |
Use of the ListView:
Layout of the ListView:
<ListView android:id="@id/android:list" android:layout_width="match_parent" android:layout_height="wrap_content" />
Android ListView usage