Android控件之RadioGroup与RadioButton(单选控件)
一、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(单选控件)的更多相关文章
- RadioGroup和RadioButton(单选框)
1.布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...
- Android控件:RadioButton(单选button)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- Android基本控件之RadioGroup
我们在手机上经常看到一堆选项,但是我们只能选择一个,那么在Android中,这个控件就叫做RadioButton,也就是单选按钮的意思,他们之所以能够达到只能选择一个的效果,是因为有一个RadioGr ...
- android应用开发--------------看RadioGroup源代码,写相似单选选项卡的集成控件(如底部导航,tab等等)
博客为 有时个哥 原创.如需转载请标明出处:http://blog.csdn.net/ls703/article/details/46694967 watermark/2/text/aHR0cDovL ...
- Android入门(八):使用RadioGroup 和RadioButton组件建立单选清单
这一章,我们学习RadioGroup 和RadioButton组件,我们新建一个项目,编码过程与前几章的项目类似. 1.建立字符串资源文件strings.xml: <resources> ...
- Android 使用RadioGroup和RadioButton实现单选效果
RadioButton和CheckBox的区别:CheckBox选中之后可以直接取消,RadioButton选中之后不能直接取消,所以一般情况下不建议单独使用.1.RadioGroup:RadioBu ...
- Android学习之RadioGroup和RadioButton
转载自:http://my.oschina.net/amigos/blog/59261 实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用.RadioG ...
- android单选按钮选择,RadioGroup,radioButton
android单选按钮选择,RadioGroup,radioButton 14. 四 / android基础 / 没有评论 单选布局绑定 如何识别选择
- ANDROID L——Material Design详解(UI控件)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...
随机推荐
- Python静态方法的使用
class Util(): @staticmethod def Func1(): print "Execute Func1!" def main(): Util.Func1()
- Poj(2679),SPFA,二级比较
题目链接:http://poj.org/problem?id=2679 嗯,思路清晰,先DFS看是不是通路,接着就是SPFA找最短路(路是费用,费用相同就比较路的长度). 超哥的代码还有一点问题,初始 ...
- 用户 NT AUTHORITY\NETWORK SERVICE 登录失败
Windows server 2003,2008 Web.Config 配置连接sql 使用 win身份验证时: 当连接sql server使用信任连接(参看Web.Config文件)时就会出这个错误 ...
- client/offset/srooll位置与关系
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 2016年11月10日 星期四 --出埃及记 Exodus 20:1
2016年11月10日 星期四 --出埃及记 Exodus 20:1 And God spoke all these words: 神吩咐这一切的话说,
- NET MVC1项目升级到MVC2最简单的方法
NET MVC1项目升级到MVC2最简单的方法 把MVC1项目升级到MVC2,最简单的做法如下: 新建MVC2项目 新建一个MVC2项目,把原来MVC1的项目文件全部拷贝到新建MVC2项目目录里,依照 ...
- MySQL基础(四)——索引
MySQL基础(四)--索引
- EXCEL中讲 10分10秒转换成610秒
前几天宝贝跟我打赌100W说我20天给她打电话不到10小时,我说绝对超过10小时了,但是由于宝贝的赖皮死活不承认,所以我被迫掉出通话记录,拿到通话记录我有点小郁闷,因为通话记录里的时间格式00分00秒 ...
- 【转】Ajax中send方法参数的使用(get/post)
Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...