AndroidÖ®UIѧϰƪʮһ£ºListView¿Ø¼þѧϰ(Ò»)
ListViewÕâ¸ö¿Ø¼þʹÓõķdz£ÆÕ±é£¬¹ØÓÚËüµÄ»ù±¾½éÉÜ£¬ÎÒÃÇÀ´¿´Ò»ÏÂAPIÖеĽéÉÜ£º
Class Overview
A view that shows items in a vertically scrolling list. The items come from the ListAdapter
associated with this view.
ListAdapterimplements Adapterandroid.widget.ListAdapter
Known Indirect Subclassesjava.lang.Objectandroid.content.Contextandroid.content.ContextWrapperandroid.view.ContextThemeWrapperandroid.app.Activityandroid.app.ListActivity
ÕýÈçÃû×Öº¬Ò壬ËüÊÇ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 sections.
ListActivity has a default layout that consists of a single, full-screen list in the center of the screen
ÎÒ¿ÉÒÔÖ±½ÓʹÓÃÄÚÖõÄĬÈÏ, full-screen list£¬µ±È»ºÜ¶àʱºòÒª×öһЩÀ©³ä£¬ÎÒÃÇ¿ÉÒÔ×Ô¶¨Òåscreen layout£¬Ê¹ÓÃsetContentView() in onCreate()À´ÏÔʾ¶¨ÒåµÄListView£¬ ²»¹ýÕâÀïÓÐÒ»ÒªÇó£¬To do this, your own view MUST contain a ListView object with the id "@android:id/list" (orlist
if it's in code)
ÕâÑùµÄÔÒòÊÇÊ²Ã´ÄØ£¿
ÔÒòÊÇÎÒÃǼ̳ÐListActivityÕâ¸öÀ࣬ʹÓÃgetListView()À´È¡µÃËü£¬ÏµÍ³ÔÚÖ´Ðи÷½·¨µÄʱºòÊǰ´ÕÕ id= list È¥²éÕÒ£¬ËùÒÔÎÒÃDZØÐ붨ÒåIdΪ" @android:id/list"¡£ÖªµÀÁ˰ɣ¡
ÎÒÃÇͨ¹ýÒ»¸öÔÚString.xmlÎļþÀïÃæÅäÖöà¸ö¹ú¼ÒµÄÃû³Æ£¬È»ºóͨ¹ýÊÊÅäÆ÷ArrayAdapterÀ´ÏÔʾÕâЩÊý¾Ýµ½ÎÒÃǵÄLIstView¿Ø¼þÖУ¬²¢ÇÒÌṩ¸ù¾ÝÓû§ÊäÈëµÄÆ¥Åä·û£¬É¸Ñ¡³öÆ¥ÅäµÄ¹ú¼ÒÃû³Æ¡£
ÔËÐнá¹û£º
´ó¼Ò¿ÉÒÔ¿´µ½¹ú¼ÒµÄÃû³ÆÒѾÏÔʾÔÚLIstView¿Ø¼þµ±ÖÐÁË£¬µ±ÎÒÃÇÊäÈë"be"ÊÇ×Ô¶¯Æ¥ÅäµÄ½á¹û½ØÍ¼£º
ÆäʵÕâ¸ö×Ô¶¯Æ¥Å书Äܼܺòµ¥£¬Ö»ÒªÔÚ´úÂëÖе÷ÓÃÕâ¾ä´úÂ룺listView.setTextFilterEnabled(true);
¹¤³ÌĿ¼½á¹¹£º
ÒÔÏÂÊÇÔ´´úÂ룺
MainActivity.java:
<?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>
ºÃÁË£¬±¾Æªµ½´Ë½áÊø£¬Íùºó»á×öÒ»¸ö¸üÌù½üÏîÄ¿µÄLIstViewʵÀý£¬ÔÙ¸ú´ó¼Ò·ÖÏí½»Á÷£¬Ð»Ð»£¡£¡