The ListView control is widely used. For a basic introduction to it, let's take a look at the introduction in the API: Class OverviewA view that shows items in a vertically scrolling list. the items come from the ListAdapter associated with this view. the data displayed in LIstView is configured through the ListAdapter interface. Generally, data is configured using a subclass of LIstView. The following describes the adapters and Their Relationships: listAdapterimplements Adapterandroid. widget. listAdapterKnown Indirect SubclassesArrayAdapter <T>, BaseAdapter, CursorAdapter, HeaderViewListAdapter, ResourceCursorAdapter, SimpleAdapter, SimpleCursorAdapter, WrapperListAdapterClass OverviewExtended Adapter that is the bridge between a ListView and the data that backs the list. frequently that data comes from a Cursor, but that is not required. the ListView can display any data provided that it is wrapped in a ListAdapter. among the many subclasses of ListAdapter, ArrayAdapter (storage array), SimpleAdapter (string), and Cursor are the most used. Adapter (data in the database ). When using the LIstView control to display data, there are two implementation methods: the first implementation method: Define the <LIstView> layout object in xml and set its related attributes, then configure and listen for events in the Activity. The second implementation method is to let your Activity class inherit from ListActivity, which can be obtained through getListView () without writing the xml file of ListView. This article will take the second method as an example for a simple example. First, let's take a look at the ListActivity class: java. lang. object upload android. content. context encryption android. content. contextWrapper extends android. view. contextThemeWrapper extends android. app. activity depends android. app. as the name implies, ListActivity is a subclass of Activity. Class OverviewAn activity that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. listActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results. binding, screen layout, and row layout are discussed in the following sewing. listActivi Ty has a default layout that consists of a single, full-screen list in the center of the screen I can directly use the built-in default, full-screen list, of course, there are a lot of time To do some expansion. We can customize screen layout and use setContentView () in onCreate () To display the defined ListView. However, there is a requirement here, To do this, your own view MUST contain a ListView object with the id "@ android: id/list" (or list if it's in code) Why? The reason is that we inherit the ListActivity class and use getListView () to retrieve it. When the system executes this method, it searches by id = list, therefore, we must define the Id as "@ android: id/list ". You know! We use a String. configure the names of multiple countries in the xml file, and then use the adapter ArrayAdapter to display the data to our LIstView control, and provide matching characters based on user input, select a country name. Running result: You can see that the country name is already displayed in the LIstView control. When we enter "be", it is the result of automatic match: in fact, this automatic match function is very simple, you only need to call this code in the Code: listView. setTextFilterEnabled (true); project directory structure: the source code is MainActivity. java: [html] package com. listview. activity; import android. app. listActivity; import android. OS. bundle; import android. view. view; import android. widget. adapterView; import android. widget. adapterView. onItemClickListener; import android. widget. arrayAdapter; im Port android. widget. listView; import android. widget. textView; import android. widget. toast; public class MainActivity extends ListActivity implements OnItemClickListener {@ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); String [] countries = getResources (). getStringArray (R. array. countries_array); // set the adapter setListAdapter (new ArrayAdapter <String> (MainActivity. this, R. layout. list_item, countries); ListView listView = getListView (); // sets the selected event listener listView for the Item. setOnItemClickListener (this); // this attribute is set to true, indicating that when the listview obtains the current focus, the matched user inputs and filters out the matched listview Items listView. setTextFilterEnabled (true) ;}@ Override public void onItemClick (AdapterView <?> Parent, View view, int position, long id) {Toast. makeText (MainActivity. this, (TextView) view ). getText (), 1 ). show () ;}} main. xml does not work here, so no code is provided here. List_item.xml: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <TextView xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: padding = "10dp" android: textSize = "16sp"> </TextView> strings. xml: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "hello"> Hello World, MainActivity! </String> <string name = "app_name"> HelloListView </string> <string-array name = "countries_array"> <item> Bahrain </item> <item> Bangladesh </item> <item> Barbados </item> <item> Belarus </item> <item> Belgium </item> <item> Belize </item> <item> Benin </item> <item> Bermuda </item> <item> Bhutan </item> <item> Bolivia </item> <item> Bosnia and Herzegovina </item> <item> botswana </item> <item> "Bouvet Island </item> <item> Brazil </item> </string-array> </resources>