Home>Article> What is the role of the ListView control in Android user interface development?

What is the role of the ListView control in Android user interface development?

藏色散人
藏色散人 Original
2020-04-16 09:32:54 3456browse

What is the role of the ListView control in Android user interface development?

What is the role of the ListView control in Android user interface development?

ListView

ListView list view control is one of the commonly used controls in Android. It directly inherits AbsListView and is a list that displays the View view in the project in a vertical manner. ListView's data items come from an adapter that inherits the ListAdapter interface.

The common properties of ListView are generally used to set the intervals, dividing lines, headers, footers and other properties of the list. The commonly used properties are as follows, and Android also provides corresponding setters/getters for them. Method:

android:divider: Use a Drawable or color to set the spacing style between data items.

android:dividerHeight: Set the spacing distance between data items.

android:entries: Set a resource ID to fill in the data items of the ListView.

android:footerDividersEnabled: Set whether to display dividing lines at the end of the list, if there is a table end.

android:headerDividerEnabled: Set whether the list header displays dividing lines, if there is a header.

ListView provides some methods for operating ListView. Here are some commonly used methods. For more information, please see the API documentation:

void addFooterView(View v): Add the footer View.

boolean removeFooterView(View v): Remove a footer View.

void addHeaderView(View v): Add a header View.

boolean removeHeaderView(View v): Remove a header View.

ListAdapter getAdapter(): Get the currently bound ListAdapter adapter.

void setAdapter(ListAdapter adapter): Set a ListAdapter adapter to the current ListView.

void setSelection(int posotion): Set the currently selected item.

long[] getCheckItemIds(): Get the currently selected item.

As a list selection control, ListView has some events that can be triggered by selected options, but it does not define these events itself, and they all inherit from the indirect parent class AdapterView. Several common events supported by ListView are as follows:

AdapterView.OnItemCLickListener: Triggered when the list item is clicked.

AdapterView.OnItemLongClickListener: Triggered when the list item is long pressed.

AdapterView.OnItemSelectedListener: Triggered when a list item is selected.

The above is the detailed content of What is the role of the ListView control in Android user interface development?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn