紫薇軟劍
“紫薇軟劍,三十歲前所用,誤傷義士不祥,乃棄之深谷。”楊過心想:“這里少了一把劍,原來是給他拋棄了,不知如何誤傷義士,這故事多半永遠無人知曉了。
今天我們學習如何利用Android平臺“紫薇軟劍”Spinner實現下拉選項列表的功能,怎么樣?紫薇軟劍也是可以拉的哦^_^。在實際生活中下拉選項列表出現的場合就太多了,像選擇語種、省份、城市、年限、薪資、職業等,真可謂是舉不勝舉。下面給出該情景的案例:
一、案例技術要點
1.從數據源采集數據分別填充ArrayAdapter和SimpleAdapter。
2.ArrayAdapter和SimpleAdapter將數據分別推向正常樣式Spinner和自定義樣式Spinner的對應視圖進行顯示。
3.為Spinner設置點擊選項監聽,獲取當前說選項的位置和ID。
二、案例代碼陳列
工程包目錄
AndroidManifest.xml
[html] view plaincopyprint?
package="cn.lynn.spinner"
android:versionCode="1"
android:versionName="1.0" >
android:minSdkVersion="8"
android:targetSdkVersion="15" />
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
android:name=".SpinnerMainActivity"
android:label="@string/app_name" >
package="cn.lynn.spinner"
android:versionCode="1"
android:versionName="1.0" >
android:minSdkVersion="8"
android:targetSdkVersion="15" />
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
android:name=".SpinnerMainActivity"
android:label="@string/app_name" >
strings.xml
[html] view plaincopyprint?
Android下拉列表Spinner
您從哪兒回來的?
您選擇的Logo是?
Android下拉列表Spinner
您從哪兒回來的?
您選擇的Logo是?
main.xml
[html] view plaincopyprint?
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/where"/>
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/what"/>
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/where"/>
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/what"/>
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
item.xml
[html] view plaincopyprint?
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/imageView"
原文轉自:http://blog.csdn.net/creativemobile/article/details/9073819