Android学习开发之路11——RadioButton和checkbox

radiobutton即单选按钮,checkbox即复选按钮也就是可以同时选择多个选项。下面的程序定义了一组单选按钮和三个复选框,来让用户选择用户相关的信息,其中单选按钮必须放在一个RadioGroup中才能实现单选的效果。



  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <TableRow>
  8. <TextView
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:text="性别:"
  12. android:textSize="11pt"
  13. />
  14. <!--定义一组单选框-->
  15. <RadioGroup
  16. android:orientation="horizontal"
  17. android:layout_gravity="center_horizontal">
  18. <!--定义两个单选框-->
  19. <RadioButtonandroid:layout_width="wrap_content"
  20. android:layout_height="wrap_content"
  21. android:text="男"
  22. />
  23. <RadioButtonandroid:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="女"
  26. />
  27. </RadioGroup>
  28. </TableRow>
  29. <TableRow>
  30. <TextView
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"
  33. android:text="喜欢的颜色:"
  34. android:textSize="11pt"
  35. />
  36. <!--定义一个垂直的线性布局-->
  37. <LinearLayoutandroid:layout_gravity="center_horizontal"
  38. android:orientation="vertical"
  39. android:layout_width="wrap_content"
  40. android:layout_height="wrap_content"
  41. >
  42. <!--定义三个复选框-->
  43. <CheckBoxandroid:layout_width="wrap_content"
  44. android:layout_height="wrap_content"
  45. android:text="红色"
  46. android:checked="true"
  47. />
  48. <CheckBoxandroid:layout_width="wrap_content"
  49. android:layout_height="wrap_content"
  50. android:text="蓝色"
  51. />
  52. <CheckBoxandroid:layout_width="wrap_content"
  53. android:layout_height="wrap_content"
  54. android:text="绿色"
  55. />
  56. </LinearLayout>
  57. </TableRow>
  58. </TableLayout>

<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableRow> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别:" android:textSize="11pt" /> <!-- 定义一组单选框 --> <RadioGroup android:orientation="horizontal" android:layout_gravity="center_horizontal"> <!-- 定义两个单选框 --> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女" /> </RadioGroup> </TableRow> <TableRow> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="喜欢的颜色:" android:textSize="11pt" /> <!-- 定义一个垂直的线性布局 --> <LinearLayout android:layout_gravity="center_horizontal" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <!-- 定义三个复选框 --> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="红色" android:checked="true" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="蓝色" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="绿色" /> </LinearLayout> </TableRow> </TableLayout>

源码资料下载:

Android 应用功能150多个实例源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值