Welcome 微信登录

首页 / 操作系统 / Linux / Android组件RadioButton、checkBox、listview、spinner综合实例及Intent传值

组件解释: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>