一、RadioGroup与RadioButton

  1、什么是RadioGroup:

    RadioButton的一个集合,提供多选机制

  2、什么是RadioButton:

    RadioButton包裹在RadioGroup中,RadioGroup表示一组RadioButton,下面可以有很多个RadioButton,但只能有一个被选中

  3、RadioGroup属性:

    android:orientation——  设置RadioGroup中RadioButton以什么形式排列(有两个值分别是:horizontal(水平排布)和 vertical(垂直排布))

二、代码演示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" > <RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" > <RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="男" /> <RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" /> </RadioGroup> </LinearLayout>
package com.muke.textview_edittext;

import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.app.Activity; public class MainActivity extends Activity implements OnCheckedChangeListener{ private RadioGroup rg; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //第一步:初始化控件(找到需要操作的控件)
rg = (RadioGroup) findViewById(R.id.radioGroup1); //第二步:实现RadioGroup的监听事件
rg.setOnCheckedChangeListener(this); } @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//checkedId表示被选中的那个RadioButton的id
switch(checkedId){
case R.id.radio0:
System.out.println("男被选中");
break;
case R.id.radio1:
System.out.println("女被选中");
break;
}
} }

Android控件之RadioGroup与RadioButton(单选控件)的更多相关文章

  1. RadioGroup和RadioButton(单选框)

    1.布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...

  2. Android控件:RadioButton(单选button)

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...

  3. Android基本控件之RadioGroup

    我们在手机上经常看到一堆选项,但是我们只能选择一个,那么在Android中,这个控件就叫做RadioButton,也就是单选按钮的意思,他们之所以能够达到只能选择一个的效果,是因为有一个RadioGr ...

  4. android应用开发--------------看RadioGroup源代码,写相似单选选项卡的集成控件(如底部导航,tab等等)

    博客为 有时个哥 原创.如需转载请标明出处:http://blog.csdn.net/ls703/article/details/46694967 watermark/2/text/aHR0cDovL ...

  5. Android入门(八):使用RadioGroup 和RadioButton组件建立单选清单

    这一章,我们学习RadioGroup 和RadioButton组件,我们新建一个项目,编码过程与前几章的项目类似. 1.建立字符串资源文件strings.xml: <resources> ...

  6. Android 使用RadioGroup和RadioButton实现单选效果

    RadioButton和CheckBox的区别:CheckBox选中之后可以直接取消,RadioButton选中之后不能直接取消,所以一般情况下不建议单独使用.1.RadioGroup:RadioBu ...

  7. Android学习之RadioGroup和RadioButton

    转载自:http://my.oschina.net/amigos/blog/59261 实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用.RadioG ...

  8. android单选按钮选择,RadioGroup,radioButton

    android单选按钮选择,RadioGroup,radioButton 14. 四 / android基础 / 没有评论   单选布局绑定 如何识别选择

  9. ANDROID L——Material Design详解(UI控件)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...

随机推荐

  1. poj1026 Cipher

    题目意思可概括为给定集合S = {1,..,n}的一个双射关系f, 求经过k次复合之后元素i对应的元素fk(i) (i∈S). 由于函数是双射,一个原像对应唯一一个像,同样一个像有唯一一个原像,考虑整 ...

  2. 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...

  3. The Happy Worm 分类: POJ 排序 2015-08-03 18:57 5人阅读 评论(0) 收藏

    The Happy Worm Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 4698 Accepted: 1047 Descr ...

  4. vsftp 使用匿名帐号登陆

    1.正常安装. 2.改配置文件:vi /etc/vsftpd/vsftpd.conf #允许匿名用户登录FTP anonymous_enable=YES #设置匿名用户的登录目录(如需要,需自己添加并 ...

  5. cmake用法(转)

    转自:http://blog.csdn.net/dbzhang800/article/details/6314073 新工作中使用到了cmake,所以找点资料学习一下,这篇讲的确实不错,转过来保存一下 ...

  6. js调用MVC3自带js验证

    验证: if ($(this).is("form")) {                        return $(this).validate().checkForm() ...

  7. SQL锁行 解决多台服务器发送统一请求并发问题

    锁行信息SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 存储过程:SET Transaction Isolation Level Read语法的四种情 ...

  8. Android权限安全(2)给基本组件自定义权限(以activity为例)

    给基本组件自定义权限(以activity为例) 1.有访问权限的activity的定义端 1.1定义权限 <permission android:name="com.example.f ...

  9. BZOJ 3460 Jc的宿舍

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3460 题意:一棵树.每个节点住一个人,这个人打水的时间为Ti.每次查询一个路径.这 ...

  10. iOS开发,推送消息 steps

    概述:推送过程简介 一.App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远程推送的申请. ...