1. 程式人生 > >Android UI控制元件之Spinner實現省市區三級聯動

Android UI控制元件之Spinner實現省市區三級聯動

城市資訊我將他放在strings.xml檔案中,具體就不給出了,資訊太大了

主xml檔案如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:focusableInTouchMode="false" >
  6. <TableLayout
  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. <TableRow
  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. <TextView
  19. android:id="@+id/province_text"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:text="省份:" >
  23. </TextView>
  24. <Spinner
  25. android:id="@+id/province_spinner"
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content" >
  28. </Spinner>
  29. </TableRow>
  30. <TableRow
  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. <TextView
  37. android:id="@+id/city_text"
  38. android:layout_width="wrap_content"
  39. android:layout_height="wrap_content"
  40. android:text="城市:" >
  41. </TextView>
  42. <Spinner
  43. android:id="@+id/city_spinner"
  44. android:layout_width="wrap_content"
  45. android:layout_height="wrap_content" >
  46. </Spinner>
  47. </TableRow>
  48. <TableRow
  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. <TextView
  55. android:id="@+id/county_text"
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:text="縣城鎮:" >
  59. </TextView>
  60. <Spinner
  61. android:id="@+id/county_spinner"
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content" >
  64. </Spinner>
  65. </TableRow>
  66. <EditText
  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. </EditText>
  74. </TableLayout>
  75. </RelativeLayout>
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent"
  5.     android:focusableInTouchMode="false" >  
  6.     <TableLayout  
  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.         <TableRow  
  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.             <TextView  
  19.                 android:id="@+id/province_text"
  20.                 android:layout_width="wrap_content"
  21.                 android:layout_height="wrap_content"
  22.                 android:text="省份:" >  
  23.             </TextView>  
  24.             <Spinner  
  25.                 android:id="@+id/province_spinner"
  26.                 android:layout_width="wrap_content"
  27.                 android:layout_height="wrap_content" >  
  28.             </Spinner>  
  29.         </TableRow>  
  30.         <TableRow  
  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.             <TextView  
  37.                 android:id="@+id/city_text"
  38.                 android:layout_width="wrap_content"
  39.                 android:layout_height="wrap_content"
  40.                 android:text="城市:" >  
  41.             </TextView>  
  42.             <Spinner  
  43.                 android:id="@+id/city_spinner"
  44.                 android:layout_width="wrap_content"
  45.                 android:layout_height="wrap_content" >  
  46.             </Spinner>  
  47.         </TableRow>  
  48.         <TableRow  
  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.