We will learn how to create a simple Android ListView and launch a new activity on selecting a single list item.
我们将学习如何创建一个简单的Android ListView并在选择单个列表项时启动新的活动。
什么是Android ListView? (What is Android ListView?)
Android ListView is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database. It’s one of the basic and most used UI components of android. The most common usages include displaying data in the form of a vertical scrolling list.
Android ListView是将多个项目分组并在垂直滚动列表中显示的视图。 列表项是使用适配器从列表或数据库等源中自动提取内容的适配器自动插入列表中的。 它是android的基本和最常用的UI组件之一。 最常见的用法包括以垂直滚动列表的形式显示数据。
使用适配器 (Using an Adapter)
An adapter actually bridges between UI components and the data source that fill data into UI Component. Adapter holds the data and send the data to adapter view, the view can take the data from adapter view and shows the data on different views like as spinner, list view, grid view etc. The adapter pulls the items out of a data source, an array for example, and then converts each item into a view which it then inserts into the ListView.
适配器实际上是UI组件和将数据填充到UI组件中的数据源之间的桥梁。 适配器保存数据并将数据发送到适配器视图,该视图可以从适配器视图获取数据,并在不同的视图(例如微调器,列表视图,网格视图等)上显示数据。适配器将项目从数据源中拉出,例如一个数组,然后将每个项目转换为一个视图,然后将其插入到ListView中。
The ListView
and GridView
are subclasses of AdapterView
and they can be populated by binding them to an Adapter, which retrieves data from an external source and creates