歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android組件RadioButton、checkBox、listview、spinner綜合實例及Intent傳值

Android組件RadioButton、checkBox、listview、spinner綜合實例及Intent傳值

日期:2017/3/1 10:47:09   编辑:Linux編程

組件解釋:

RadioButton單選按鈕

checkBox復選框是一種有雙狀態按鈕的特殊類型,可以選中或者不選中。

listview列表

列表的顯示需要三個元素:1.ListVeiw 用來展示列表的View。2.適配器 用來把數據映射到ListView上的中。3.數據 具體的將被映射的字符串,圖片,或者基本組件。

根據列表的適配器類型,列表分為三種,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter其中以ArrayAdapter最為簡單,只能展示一行字。SimpleAdapter有最好的擴充性,可以自定義出各種效果。SimpleCursorAdapter可以認為是SimpleAdapter對數據庫的簡單結合,可以方面的把數據庫的內容以列表的形式展示出來。

spiner下拉列表(Spinner)是一個每次只能選擇所有項中一項的部件。它的項來自於與之相關聯的適配器中。

Intent英文裡 Intent是“意向、打算”的意思,其實就是告訴別人你的意圖的意思了,這麼理解Android裡面的Intent也就不難了。

本文原碼下載地址:

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /pub/Android源碼集錦/2011年/12月/Android組件RadioButton、checkBox、listview、spinner綜合實例及Intent傳值/

費話不多說,直接先看效果圖:

main.xml布局文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:layout_gravity="center"
  10. android:gravity="center"
  11. android:text="@string/hello"
  12. android:textSize="30dp"
  13. android:textStyle="bold" />
  14. <TableLayout
  15. android:layout_width="fill_parent"
  16. android:layout_height="wrap_content"
  17. android:stretchColumns="1" >
  18. <TableRow >
  19. <TextView
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:layout_gravity="center"
  23. android:text="用戶名:" />
  24. <EditText
  25. android:id="@+id/username"
  26. android:layout_width="fill_parent"
  27. android:layout_height="wrap_content"
  28. android:hint="請輸入用戶名!!!" />
  29. </TableRow>
  30. <TableRow >
  31. <TextView
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"
  34. android:layout_gravity="center"
  35. android:text="密碼:" />
  36. <EditText
  37. android:id="@+id/password"
  38. android:layout_width="fill_parent"
  39. android:layout_height="wrap_content"
  40. android:hint="請輸入密碼!!!" />
  41. </TableRow>
  42. <TableRow >
  43. <TextView
  44. android:layout_width="wrap_content"
  45. android:layout_height="wrap_content"
  46. android:layout_gravity="center"
  47. android:text="性別:"
  48. android:textSize="20dp" />
  49. <RadioGroup
  50. android:id="@+id/sex"
  51. android:layout_width="fill_parent"
  52. android:layout_height="wrap_content"
  53. android:checkedButton="@+id/woman"
  54. android:orientation="horizontal" >
  55. <RadioButton
  56. android:id="@+id/nan"
  57. android:text="男" />
  58. <RadioButton
  59. android:id="@id/woman"
  60. android:text="女" />
  61. </RadioGroup>
  62. </TableRow>
  63. <TableRow >
  64. <TextView
  65. android:layout_width="fill_parent"
  66. android:layout_height="wrap_content"
  67. android:layout_gravity="center"
  68. android:text="愛好:"
  69. android:textSize="20dp" />
  70. <TableLayout
  71. android:id="@+id/table"
  72. android:layout_width="fill_parent"
  73. android:layout_height="wrap_content"
  74. android:stretchColumns="*" >
  75. <TableRow >
  76. <CheckBox
  77. android:id="@+id/cb1"
  78. android:layout_width="match_parent"
  79. android:layout_height="wrap_content"
  80. android:text="足球" />
  81. <CheckBox
  82. android:id="@+id/cb2"
  83. android:layout_width="match_parent"
  84. android:layout_height="wrap_content"
  85. android:text="籃球" />
  86. </TableRow>
  87. <TableRow >
  88. <CheckBox
  89. android:id="@+id/cb3"
  90. android:layout_width="match_parent"
  91. android:layout_height="wrap_content"
  92. android:text="游戲" />
  93. <CheckBox
  94. android:id="@+id/cb4"
  95. android:layout_width="match_parent"
  96. android:layout_height="wrap_content"
  97. android:text="游泳" />
  98. </TableRow>
  99. </TableLayout>
  100. </TableRow>
  101. <TableRow >
  102. <TextView
  103. android:layout_width="fill_parent"
  104. android:layout_height="wrap_content"
  105. android:text="學歷:" />
  106. <Spinner
  107. android:id="@+id/sports"
  108. android:layout_width="match_parent"
  109. android:layout_height="wrap_content"
  110. android:entries="@array/educate"
  111. android:prompt="@string/educate" />
  112. </TableRow>
  113. </TableLayout>
  114. <Button
  115. android:layout_width="100dp"
  116. android:layout_height="wrap_content"
  117. android:layout_gravity="center"
  118. android:id="@+id/button"
  119. android:text="注冊" />
  120. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved