上一篇文章中了解到了Spinner的简单用法,知道了Spinner的数据源一般有两种形式。

XML文件和数组的方式。这次的内容主要是想在Spinner上实现省市区三级联动,话不多说了

直接上效果图吧!

之Spinner控件

城市信息我将他放在strings.xml文件中,具体就不给出了,信息太大了

主xml文件如下:

[java] view plaincopyprint?

  1. "1.0" encoding="utf-8"?>

  2. "http://schemas.android.com/apk/res/android"

  3. android:layout_width="fill_parent"

  4. android:layout_height="fill_parent"

  5. android:focusableInTouchMode="false" >

  6.  

  7. android:id="@+id/tableLayout1"

  8. android:layout_width="fill_parent"

  9. android:layout_height="fill_parent"

  10. android:paddingTop="20px"

  11. android:stretchColumns="1" >

  12.  

  13. android:id="@+id/tableRow1"

  14. android:layout_width="wrap_content"

  15. android:layout_height="wrap_content"

  16. android:paddingTop="10px"

  17. android:scrollbarAlwaysDrawVerticalTrack="false" >

  18.  

  19. android:id="@+id/province_text"

  20. android:layout_width="wrap_content"

  21. android:layout_height="wrap_content"

  22. android:text="省份:" >

  23.  

  24.  

  25. android:id="@+id/province_spinner"

  26. android:layout_width="wrap_content"

  27. android:layout_height="wrap_content" >

  28.  

  29.  

  30.  

  31. android:id="@+id/tableRow2"

  32. android:layout_width="wrap_content"

  33. android:layout_height="wrap_content"

  34. android:paddingTop="10px"

  35. android:scrollbarAlwaysDrawVerticalTrack="false" >

  36.  

  37. android:id="@+id/city_text"

  38. android:layout_width="wrap_content"

  39. android:layout_height="wrap_content"

  40. android:text="城市:" >

  41.  

  42.  

  43. android:id="@+id/city_spinner"

  44. android:layout_width="wrap_content"

  45. android:layout_height="wrap_content" >

  46.  

  47.  

  48.  

  49. android:id="@+id/tableRow3"

  50. android:layout_width="wrap_content"

  51. android:layout_height="wrap_content"

  52. android:paddingTop="10px"

  53. android:scrollbarAlwaysDrawVerticalTrack="false" >

  54.  

  55. android:id="@+id/county_text"

  56. android:layout_width="wrap_content"

  57. android:layout_height="wrap_content"

  58. android:text="县城镇:" >

  59.  

  60.  

  61. android:id="@+id/county_spinner"

  62. android:layout_width="wrap_content"

  63. android:layout_height="wrap_content" >

  64.  

  65.  

  66.  

  67. android:id="@+id/display_edit"

  68. android:layout_width="wrap_content"

  69. android:layout_height="wrap_content"

  70. android:focusableInTouchMode="false"

  71. android:hint="输出结果"

  72. android:paddingTop="10px" >

  73.  

  74.  

  75.  

  76.  

MainAcitivty问价如下:

[java] view plaincopyprint?

  1. /**

  2. * 省市县联动

  3. *

  4. * kiritor

  5. *

  6. * 2011.3.17

  7. */

  8. package com.kiritor.ui_spinner_baseadapter;

  9.  

  10. import android.app.Activity;

  11. import android.os.Bundle;

  12. import android.util.Log;

  13. import android.view.View;

  14. import android.widget.AdapterView;

  15. import android.widget.ArrayAdapter;

  16. import android.widget.EditText;

  17. import android.widget.Spinner;

  18. import android.widget.AdapterView.OnItemSelectedListener;

  19.  

  20. public class MainActivityextends Activity {

  21. private Spinner province_spinner;

  22. private Spinner city_spinner;

  23. private Spinner county_spinner;

  24. private Integer provinceId, cityId;

  25. private EditText display;

  26. private String strProvince, strCity, strCounty;

  27. //市,自治区集合

  28. private int[] city = { R.array.beijin_province_item,

  29. R.array.tianjin_province_item, R.array.heibei_province_item,

  30. R.array.shanxi1_province_item, R.array.neimenggu_province_item,

  31. R.array.liaoning_province_item, R.array.jilin_province_item,

  32. R.array.heilongjiang_province_item, R.array.shanghai_province_item,

  33. R.array.jiangsu_province_item, R.array.zhejiang_province_item,

  34. R.array.anhui_province_item, R.array.fujian_province_item,

  35. R.array.jiangxi_province_item, R.array.shandong_province_item,

  36. R.array.henan_province_item, R.array.hubei_province_item,

  37. R.array.hunan_province_item, R.array.guangdong_province_item,

  38. R.array.guangxi_province_item, R.array.hainan_province_item,

  39. R.array.chongqing_province_item, R.array.sichuan_province_item,

  40. R.array.guizhou_province_item, R.array.yunnan_province_item,

  41. R.array.xizang_province_item, R.array.shanxi2_province_item,

  42. R.array.gansu_province_item, R.array.qinghai_province_item,

  43. R.array.linxia_province_item, R.array.xinjiang_province_item,

  44. R.array.hongkong_province_item, R.array.aomen_province_item,

  45. R.array.taiwan_province_item };

  46. private int[] countyOfBeiJing = { R.array.beijin_city_item };

  47. private int[] countyOfTianJing = { R.array.tianjin_city_item };

  48. private int[] countyOfHeBei = { R.array.shijiazhuang_city_item,

  49. R.array.tangshan_city_item, R.array.qinghuangdao_city_item,

  50. R.array.handan_city_item, R.array.xingtai_city_item,

  51. R.array.baoding_city_item, R.array.zhangjiakou_city_item,

  52. R.array.chengde_city_item, R.array.cangzhou_city_item,

  53. R.array.langfang_city_item, R.array.hengshui_city_item };

  54. private int[] countyOfShanXi1 = { R.array.taiyuan_city_item,

  55. R.array.datong_city_item, R.array.yangquan_city_item,

  56. R.array.changzhi_city_item, R.array.jincheng_city_item,

  57. R.array.shuozhou_city_item, R.array.jinzhong_city_item,

  58. R.array.yuncheng_city_item, R.array.xinzhou_city_item,

  59. R.array.linfen_city_item, R.array.lvliang_city_item };

  60. private int[] countyOfNeiMengGu = { R.array.huhehaote_city_item,

  61. R.array.baotou_city_item, R.array.wuhai_city_item,

  62. R.array.chifeng_city_item, R.array.tongliao_city_item,

  63. R.array.eerduosi_city_item, R.array.hulunbeier_city_item,

  64. R.array.bayannaoer_city_item, R.array.wulanchabu_city_item,

  65. R.array.xinganmeng_city_item, R.array.xilinguolemeng_city_item,

  66. R.array.alashanmeng_city_item };

  67. private int[] countyOfLiaoNing = { R.array.shenyang_city_item,

  68. R.array.dalian_city_item, R.array.anshan_city_item,

  69. R.array.wushun_city_item, R.array.benxi_city_item,

  70. R.array.dandong_city_item, R.array.liaoning_jinzhou_city_item,

  71. R.array.yingkou_city_item, R.array.fuxin_city_item,

  72. R.array.liaoyang_city_item, R.array.panjin_city_item,

  73. R.array.tieling_city_item, R.array.zhaoyang_city_item,

  74. R.array.huludao_city_item };

  75. private int[] countyOfJiLin = { R.array.changchun_city_item,

  76. R.array.jilin_city_item, R.array.siping_city_item,

  77. R.array.liaoyuan_city_item, R.array.tonghua_city_item,

  78. R.array.baishan_city_item, R.array.songyuan_city_item,

  79. R.array.baicheng_city_item, R.array.yanbian_city_item };

  80. private int[] countyOfHeiLongJiang = { R.array.haerbing_city_item,

  81. R.array.qiqihaer_city_item, R.array.jixi_city_item,

  82. R.array.hegang_city_item, R.array.shuangyashan_city_item,

  83. R.array.daqing_city_item, R.array.heilongjiang_yichun_city_item,

  84. R.array.jiamusi_city_item, R.array.qitaihe_city_item,

  85. R.array.mudanjiang_city_item, R.array.heihe_city_item,

  86. R.array.suihua_city_item, R.array.daxinganling_city_item };

  87. private int[] countyOfShangHai = { R.array.shanghai_city_item };

  88.  

  89. private int[] countyOfJiangSu = { R.array.nanjing_city_item,

  90. R.array.wuxi_city_item, R.array.xuzhou_city_item,

  91. R.array.changzhou_city_item, R.array.nanjing_suzhou_city_item,

  92. R.array.nantong_city_item, R.array.lianyungang_city_item,

  93. R.array.huaian_city_item, R.array.yancheng_city_item,

  94. R.array.yangzhou_city_item, R.array.zhenjiang_city_item,

  95. R.array.jiangsu_taizhou_city_item, R.array.suqian_city_item };

  96. private int[] countyOfZheJiang = { R.array.hangzhou_city_item,

  97. R.array.ningbo_city_item, R.array.wenzhou_city_item,

  98. R.array.jiaxing_city_item, R.array.huzhou_city_item,

  99. R.array.shaoxing_city_item, R.array.jinhua_city_item,

  100. R.array.quzhou_city_item, R.array.zhoushan_city_item,

  101. R.array.zejiang_huzhou_city_item, R.array.lishui_city_item };

  102. private int[] countyOfAnHui = { R.array.hefei_city_item,

  103. R.array.wuhu_city_item, R.array.bengbu_city_item,

  104. R.array.huainan_city_item, R.array.maanshan_city_item,

  105. R.array.huaibei_city_item, R.array.tongling_city_item,

  106. R.array.anqing_city_item, R.array.huangshan_city_item,

  107. R.array.chuzhou_city_item, R.array.fuyang_city_item,

  108. R.array.anhui_suzhou_city_item, R.array.chaohu_city_item,

  109. R.array.luan_city_item, R.array.haozhou_city_item,

  110. R.array.chizhou_city_item, R.array.xuancheng_city_item };

  111. private int[] countyOfFuJian = { R.array.huzhou_city_item,

  112. R.array.xiamen_city_item, R.array.putian_city_item,

  113. R.array.sanming_city_item, R.array.quanzhou_city_item,

  114. R.array.zhangzhou_city_item, R.array.nanp_city_item,

  115. R.array.longyan_city_item, R.array.ningde_city_item };

  116. private int[] countyOfJiangXi = { R.array.nanchang_city_item,

  117. R.array.jingdezhen_city_item, R.array.pingxiang_city_item,

  118. R.array.jiujiang_city_item, R.array.xinyu_city_item,

  119. R.array.yingtan_city_item, R.array.ganzhou_city_item,

  120. R.array.jian_city_item, R.array.jiangxi_yichun_city_item,

  121. R.array.jiangxi_wuzhou_city_item, R.array.shangrao_city_item };

  122. private int[] countyOfShanDong = { R.array.jinan_city_item,

  123. R.array.qingdao_city_item, R.array.zaobo_city_item,

  124. R.array.zaozhuang_city_item, R.array.dongying_city_item,

  125. R.array.yantai_city_item, R.array.weifang_city_item,

  126. R.array.jining_city_item, R.array.taian_city_item,

  127. R.array.weihai_city_item, R.array.rizhao_city_item,

  128. R.array.laiwu_city_item, R.array.linxi_city_item,

  129. R.array.dezhou_city_item, R.array.liaocheng_city_item,

  130. R.array.shandong_bingzhou_city_item, R.array.heze_city_item };

  131. private int[] countyOfHeNan = { R.array.zhenshou_city_item,

  132. R.array.kaifang_city_item, R.array.luoyang_city_item,

  133. R.array.kaipingshan_city_item, R.array.anyang_city_item,

  134. R.array.hebi_city_item, R.array.xinxiang_city_item,

  135. R.array.jiaozuo_city_item, R.array.buyang_city_item,

  136. R.array.xuchang_city_item, R.array.leihe_city_item,

  137. R.array.sanmenxia_city_item, R.array.nanyang_city_item,

  138. R.array.shangqiu_city_item, R.array.xinyang_city_item,

  139. R.array.zhoukou_city_item, R.array.zhumadian_city_item };

  140. private int[] countyOfHuBei = { R.array.wuhan_city_item,

  141. R.array.huangshi_city_item, R.array.shiyan_city_item,

  142. R.array.yichang_city_item, R.array.xiangpan_city_item,

  143. R.array.erzhou_city_item, R.array.jinmen_city_item,

  144. R.array.xiaogan_city_item, R.array.hubei_jinzhou_city_item,

  145. R.array.huanggang_city_item, R.array.xianning_city_item,

  146. R.array.suizhou_city_item, R.array.enshi_city_item,

  147. R.array.shenglongjia_city_item };

  148.  

  149. private int[] countyOfHuNan = { R.array.changsha_city_item,

  150. R.array.zhuzhou_city_item, R.array.xiangtan_city_item,

  151. R.array.hengyang_city_item, R.array.shaoyang_city_item,

  152. R.array.yueyang_city_item, R.array.changde_city_item,

  153. R.array.zhangjiajie_city_item, R.array.yiyang_city_item,

  154. R.array.hunan_bingzhou_city_item, R.array.yongzhou_city_item,

  155. R.array.huaihua_city_item, R.array.loudi_city_item,

  156. R.array.xiangxi_city_item };

  157. private int[] countyOfGuangDong = { R.array.guangzhou_city_item,

  158. R.array.shaoguan_city_item, R.array.shenzhen_city_item,

  159. R.array.zhuhai_city_item, R.array.shantou_city_item,

  160. R.array.foshan_city_item, R.array.jiangmen_city_item,

  161. R.array.zhangjiang_city_item, R.array.maoming_city_item,

  162. R.array.zhaoqing_city_item, R.array.huizhou_city_item,

  163. R.array.meizhou_city_item, R.array.shanwei_city_item,

  164. R.array.heyuan_city_item, R.array.yangjiang_city_item,

  165. R.array.qingyuan_city_item, R.array.dongguan_city_item,

  166. R.array.zhongshan_city_item, R.array.chaozhou_city_item,

  167. R.array.jiyang_city_item, R.array.yunfu_city_item };

  168. private int[] countyOfGuangXi = { R.array.nanning_city_item,

  169. R.array.liuzhou_city_item, R.array.guilin_city_item,

  170. R.array.guangxi_wuzhou_city_item, R.array.beihai_city_item,

  171. R.array.fangchenggang_city_item, R.array.qinzhou_city_item,

  172. R.array.guigang_city_item, R.array.yuelin_city_item,

  173. R.array.baise_city_item, R.array.hezhou_city_item,

  174. R.array.hechi_city_item, R.array.laibing_city_item,

  175. R.array.chuangzuo_city_item };

  176. private int[] countyOfHaiNan = { R.array.haikou_city_item,

  177. R.array.sanya_city_item };

  178. private int[] countyOfChongQing = { R.array.chongqing_city_item };

  179. private int[] countyOfSiChuan = { R.array.chengdu_city_item,

  180. R.array.zigong_city_item, R.array.panzhihua_city_item,

  181. R.array.luzhou_city_item, R.array.deyang_city_item,

  182. R.array.mianyang_city_item, R.array.guangyuan_city_item,

  183. R.array.suining_city_item, R.array.neijiang_city_item,

  184. R.array.leshan_city_item, R.array.nanchong_city_item,

  185. R.array.meishan_city_item, R.array.yibing_city_item,

  186. R.array.guangan_city_item, R.array.dazhou_city_item,

  187. R.array.yaan_city_item, R.array.bazhong_city_item,

  188. R.array.ziyang_city_item, R.array.abei_city_item,

  189. R.array.ganmu_city_item, R.array.liangshan_city_item };

  190. private int[] countyOfGuiZhou = { R.array.guiyang_city_item,

  191. R.array.lupanshui_city_item, R.array.zhunyi_city_item,

  192. R.array.anshun_city_item, R.array.tongren_city_item,

  193. R.array.qingxinan_city_item, R.array.biji_city_item,

  194. R.array.qingdongnan_city_item, R.array.qingnan_city_item };

  195. private int[] countyOfYunNan = { R.array.kunming_city_item,

  196. R.array.qujing_city_item, R.array.yuexi_city_item,

  197. R.array.baoshan_city_item, R.array.zhaotong_city_item,

  198. R.array.lijiang_city_item, R.array.simao_city_item,

  199. R.array.lingcang_city_item, R.array.chuxiong_city_item,

  200. R.array.honghe_city_item, R.array.wenshan_city_item,

  201. R.array.xishuangbanna_city_item, R.array.dali_city_item,

  202. R.array.dehuang_city_item, R.array.nujiang_city_item,

  203. R.array.diqing_city_item };

  204. private int[] countyOfXiZang = { R.array.lasa_city_item,

  205. R.array.changdu_city_item, R.array.shannan_city_item,

  206. R.array.rgeze_city_item, R.array.naqu_city_item,

  207. R.array.ali_city_item, R.array.linzhi_city_item };

  208.  

  209. private int[] countyOfShanXi2 = { R.array.xian_city_item,

  210. R.array.tongchuan_city_item, R.array.baoji_city_item,

  211. R.array.xianyang_city_item, R.array.weinan_city_item,

  212. R.array.yanan_city_item, R.array.hanzhong_city_item,

  213. R.array.yulin_city_item, R.array.ankang_city_item,

  214. R.array.shangluo_city_item };

  215. private int[] countyOfGanSu = { R.array.lanzhou_city_item,

  216. R.array.jiayuguan_city_item, R.array.jinchang_city_item,

  217. R.array.baiyin_city_item, R.array.tianshui_city_item,

  218. R.array.wuwei_city_item, R.array.zhangyue_city_item,

  219. R.array.pingliang_city_item, R.array.jiuquan_city_item,

  220. R.array.qingyang_city_item, R.array.dingxi_city_item,

  221. R.array.longnan_city_item, R.array.linxia_city_item,

  222. R.array.gannan_city_item };

  223. private int[] countyOfQingHai = { R.array.xining_city_item,

  224. R.array.haidong_city_item, R.array.haibai_city_item,

  225. R.array.huangnan_city_item, R.array.hainan_city_item,

  226. R.array.guluo_city_item, R.array.yushu_city_item,

  227. R.array.haixi_city_item };

  228. private int[] countyOfNingXia = { R.array.yinchuan_city_item,

  229. R.array.shizuishan_city_item, R.array.wuzhong_city_item,

  230. R.array.guyuan_city_item, R.array.zhongwei_city_item };

  231. private int[] countyOfXinJiang = { R.array.wulumuqi_city_item,

  232. R.array.kelamayi_city_item, R.array.tulyfan_city_item,

  233. R.array.hami_city_item, R.array.changji_city_item,

  234. R.array.boertala_city_item, R.array.bayinguolen_city_item,

  235. R.array.akesu_city_item, R.array.kemuleisu_city_item,

  236. R.array.geshen_city_item, R.array.hetian_city_item,

  237. R.array.yili_city_item, R.array.tacheng_city_item,

  238. R.array.aleitai_city_item, R.array.shihezi_city_item,

  239. R.array.alaer_city_item, R.array.tumushihe_city_item,

  240. R.array.wujiaqu_city_item };

  241. private int[] countyOfHongKong = {};

  242. private int[] countyOfAoMen = {};

  243. private int[] countyOfTaiWan = {};

  244.  

  245. private ArrayAdapter province_adapter;

  246. private ArrayAdapter city_adapter;

  247. private ArrayAdapter county_adapter;

  248.  

  249. @Override

  250. public void onCreate(Bundle savedInstanceState) {

  251. super.onCreate(savedInstanceState);

  252. setContentView(R.layout.activity_main);

  253. loadSpinner();

  254. }

  255.  

  256. private void loadSpinner() {

  257. display = (EditText) findViewById(R.id.display_edit);

  258. province_spinner = (Spinner) findViewById(R.id.province_spinner);

  259. //绑定省份的数据

  260. province_spinner.setPrompt("请选择省份");

  261. province_adapter = ArrayAdapter.createFromResource(this,

  262. R.array.province_item, android.R.layout.simple_spinner_item);

  263. province_adapter

  264. .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

  265. province_spinner.setAdapter(province_adapter);

  266. // select(province_spinner, province_adapter, R.array.province_item);

  267. //添加监听,一开始的时候城市,县区的内容是不显示的而是根据省的内容进行联动

  268. province_spinner

  269. .setOnItemSelectedListener(new OnItemSelectedListener() {

  270. @Override

  271. public void onItemSelected(AdapterViewarg0, View arg1,

  272. int arg2, long arg3) {

  273. provinceId = province_spinner.getSelectedItemPosition();

  274. strProvince = province_spinner.getSelectedItem()

  275. .toString();//得到选择的内容,也就是省的名字

  276. city_spinner = (Spinner) findViewById(R.id.city_spinner);

  277.  

  278.  

  279. if (true) {

  280. System.out.println("province: "

  281. + province_spinner.getSelectedItem()

  282. .toString() + provinceId.toString());

  283.  

  284.  

  285. county_spinner = (Spinner) findViewById(R.id.county_spinner);

  286. city_spinner = (Spinner) findViewById(R.id.city_spinner);

  287. city_spinner.setPrompt("请选择城市");//设置标题

  288. select(city_spinner, city_adapter, city[provinceId]);//城市一级的数据绑定

  289. /*通过这个city[provinceId]指明了该省市的City集合

  290. * R。array.beijing*/

  291. city_spinner

  292. .setOnItemSelectedListener(new OnItemSelectedListener() {

  293.  

  294. @Override

  295. public void onItemSelected(

  296. AdapterViewarg0, View arg1,

  297. int arg2,  long arg3) {

  298. cityId = city_spinner

  299. .getSelectedItemPosition();//得到city的id

  300. strCity = city_spinner

  301. .getSelectedItem()

  302. .toString();//得到city的内容

  303. Log.v("test",  "city: "

  304. + city_spinner

  305. .getSelectedItem()

  306. .toString()//输出测试一下

  307. + cityId.toString());

  308. if (true) {

  309. //这里开始设置县区一级的内容

  310. county_spinner = (Spinner) findViewById(R.id.county_spinner);

  311. county_spinner

  312. .setPrompt("请选择县区");

  313. switch (provinceId) {

  314. case 0:

  315. select(county_spinner,

  316. county_adapter,

  317. countyOfBeiJing[cityId]);

  318. break;

  319. case 1:

  320. select(county_spinner,

  321. county_adapter,

  322. countyOfTianJing[cityId]);

  323. break;

  324. case 2:

  325. select(county_spinner,

  326. county_adapter,

  327. countyOfHeBei[cityId]);

  328. break;

  329. case 3:

  330. select(county_spinner,

  331. county_adapter,

  332. countyOfShanXi1[cityId]);

  333. break;

  334. case 4:

  335. select(county_spinner,

  336. county_adapter,

  337. countyOfNeiMengGu[cityId]);

  338. break;

  339. case 5:

  340. select(county_spinner,

  341. county_adapter,

  342. countyOfLiaoNing[cityId]);

  343. break;

  344. case 6:

  345. select(county_spinner,

  346. county_adapter,

  347. countyOfJiLin[cityId]);

  348. break;

  349. case 7:

  350. select(county_spinner,

  351. county_adapter,

  352. countyOfHeiLongJiang[cityId]);

  353. break;

  354. case 8:

  355. select(county_spinner,

  356. county_adapter,

  357. countyOfShangHai[cityId]);

  358. break;

  359. case 9:

  360. select(county_spinner,

  361. county_adapter,

  362. countyOfJiangSu[cityId]);

  363. break;

  364. case 10:

  365. select(county_spinner,

  366. county_adapter,

  367. countyOfZheJiang[cityId]);

  368. break;

  369. case 11:

  370. select(county_spinner,

  371. county_adapter,

  372. countyOfAnHui[cityId]);

  373. break;

  374. case 12:

  375. select(county_spinner,

  376. county_adapter,

  377. countyOfFuJian[cityId]);

  378. break;

  379. case 13:

  380. select(county_spinner,

  381. county_adapter,

  382. countyOfJiangXi[cityId]);

  383. break;

  384. case 14:

  385. select(county_spinner,

  386. county_adapter,

  387. countyOfShanDong[cityId]);

  388. break;

  389. case 15:

  390. select(county_spinner,

  391. county_adapter,

  392. countyOfHeNan[cityId]);

  393. break;

  394. case 16:

  395. select(county_spinner,

  396. county_adapter,

  397. countyOfHuBei[cityId]);

  398. break;

  399. case 17:

  400. select(county_spinner,

  401. county_adapter,

  402. countyOfHuNan[cityId]);

  403. break;

  404. case 18:

  405. select(county_spinner,

  406. county_adapter,

  407. countyOfGuangDong[cityId]);

  408. break;

  409. case 19:

  410. select(county_spinner,

  411. county_adapter,

  412. countyOfGuangXi[cityId]);

  413. break;

  414. case 20:

  415. select(county_spinner,

  416. county_adapter,

  417. countyOfHaiNan[cityId]);

  418. break;

  419. case 21:

  420. select(county_spinner,

  421. county_adapter,

  422. countyOfChongQing[cityId]);

  423. break;

  424. case 22:

  425. select(county_spinner,

  426. county_adapter,

  427. countyOfSiChuan[cityId]);

  428. break;

  429. case 23:

  430. select(county_spinner,

  431. county_adapter,

  432. countyOfGuiZhou[cityId]);

  433. break;

  434. case 24:

  435. select(county_spinner,

  436. county_adapter,

  437. countyOfYunNan[cityId]);

  438. break;

  439. case 25:

  440. select(county_spinner,

  441. county_adapter,

  442. countyOfXiZang[cityId]);

  443. break;

  444. case 26:

  445. select(county_spinner,

  446. county_adapter,

  447. countyOfShanXi2[cityId]);

  448. break;

  449. case 27:

  450. select(county_spinner,

  451. county_adapter,

  452. countyOfGanSu[cityId]);

  453. break;

  454. case 28:

  455. select(county_spinner,

  456. county_adapter,

  457. countyOfQingHai[cityId]);

  458. break;

  459. case 29:

  460. select(county_spinner,

  461. county_adapter,

  462. countyOfNingXia[cityId]);

  463. break;

  464. case 30:

  465. select(county_spinner,

  466. county_adapter,

  467. countyOfXinJiang[cityId]);

  468. break;

  469. case 31:

  470. select(county_spinner,

  471. county_adapter,

  472. countyOfHongKong[cityId]);

  473. break;

  474. case 32:

  475. select(county_spinner,

  476. county_adapter,

  477. countyOfAoMen[cityId]);

  478. break;

  479. case 33:

  480. select(county_spinner,

  481. county_adapter,

  482. countyOfTaiWan[cityId]);

  483. break;

  484.  

  485. default:

  486. break;

  487. }

  488.  

  489. county_spinner

  490. .setOnItemSelectedListener(new OnItemSelectedListener() {

  491.  

  492. @Override

  493. public void onItemSelected(

  494. AdapterViewarg0,

  495. View arg1,

  496. int arg2,

  497. long arg3) {

  498. strCounty = county_spinner

  499. .getSelectedItem()

  500. .toString();

  501. display.setText(strProvince

  502. + "-"

  503. + strCity

  504. + "-"

  505. + strCounty);

  506. }

  507.  

  508. @Override

  509. public void onNothingSelected(

  510. AdapterViewarg0) {

  511.  

  512. }

  513.  

  514. });

  515. }

  516. }

  517.  

  518. @Override

  519. public void onNothingSelected(

  520. AdapterViewarg0) {

  521. // TODO Auto-generated method stub

  522.  

  523. }

  524.  

  525. });

  526. }

  527. }

  528.  

  529. @Override

  530. public void onNothingSelected(AdapterViewarg0) {

  531.  

  532. }

  533. });

  534.  

  535. }

  536. /*通过方法动态的添加适配器*/

  537. private void select(Spinner spin, ArrayAdapter adapter,

  538. int arry) {

  539. //注意这里的arry不仅仅但是一个整形,他代表了一个数组!

  540. adapter = ArrayAdapter.createFromResource(this, arry,

  541. android.R.layout.simple_spinner_item);

  542. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

  543. spin.setAdapter(adapter);

  544. // spin.setSelection(0,true);

 

稳定

产品可用性高于99.9%

贴心

全国7*24小时客服热线

专业

产品经理在线技术支持

快速

快速上线运营快

承诺

我们选择声誉

坚持

10年专注高端品质开发
  • 返回顶部