歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android常用適配器控件

Android常用適配器控件

日期:2017/3/1 9:53:28   编辑:Linux編程

列表控件用於顯示數據集合,Android不是使用一種類型的控件管理顯示和數據,而是將這兩項功能分布用列表控件和適配器來實現。列表控件擴展了android.widget.AdapterView的類,包括ListView、GridView、Spinner和Gallery。

1)基本的列表控件ListView

ListView控件垂直顯示一組項,通常通過編寫一個擴展android.app.ListActivity的新活動來使用ListView。ListActivity包含一個ListView,可以調用setListAdapter()方法來為ListView設置數據。前面介紹過適配器將列表控件鏈接到數據,幫助為列表控件准備子視圖,可單擊ListView中的某一項來立即執行操作,或選擇它們以稍後對所選擇項集合采取操作。

Demo1:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView>

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="doClick"
android:text="Submit Selection" >
</Button>

</LinearLayout>

Copyright © Linux教程網 All Rights Reserved