RadioGroup和RadioButton(单选框)

1.布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content" > <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>
2.绑定事件(实现接口,注意导包)
package com.example.test2; import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener; public class MainActivity extends Activity implements OnCheckedChangeListener { private Button login_button;
private Button reset;
private RadioGroup rg;
private Button other;
private CheckBox checkBox1;
private Button myButton; /*
* @Override protected void onCreate(Bundle savedInstanceState) {
* super.onCreate(savedInstanceState);
* setContentView(R.layout.activity_radiobutton);
*
* login_button = (Button) this.findViewById(R.id.loginButton); checkBox1 =
* (CheckBox) findViewById(R.id.checkBox1);
* checkBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
*
* @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1)
* { // arg1代表是否选中 Log.i("tag", arg1 + ""); if (arg1) { Log.i("tag",
* checkBox1.getText().toString()); }
*
* } }); }
*/ // 单选框
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radiobutton); rg = (RadioGroup) this.findViewById(R.id.radioGroup1);
rg.setOnCheckedChangeListener(this);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public void onCheckedChanged(RadioGroup arg0, int checkId) {
// TODO Auto-generated method stub
switch(checkId){
case R.id.radio0:
Log.i("tag", "当前选中男");
break ;
case R.id.radio1:
Log.i("tag", "当前选中女");
break ;
default:
break ;
}
} }
3.效果:


RadioGroup和RadioButton(单选框)的更多相关文章
- Tkinter 之RadioButton单选框标签
一.参数说明 语法 作用 Radiobutton(root,text='xxxx') 单选框文本显示内容 Radiobutton(root,variable=color) 单选框索引变量,通过变量的值 ...
- tkiner中Radiobutton单选框控件(七)
Radiobutton控件 由于本次内容中好多知识都是之前重复解释过的,本次就不做解释了.不太清楚的内容请参考tkinter1-6节中的内容 import tkinter wuya = tkinter ...
- tkinter中Radiobutton单选框控件(七)
Radiobutton控件 由于本次内容中好多知识都是之前重复解释过的,本次就不做解释了.不太清楚的内容请参考tkinter1-6节中的内容 import tkinter wuya = tkinter ...
- Qt Quick 常用元素:RadioButton(单选框),CheckBox(复选框) 与 GroupBox(分组框)
先介绍一下 ExclusiveGroup. ExclusiveGroup (互斥分组)本身是不可见元素,用于将若干个可选择元素组合在一起, 供用户选择其中的一个选项.你可以在 ExclusiveGro ...
- Android初级教程小案例之单选框RadioGroup与复选框CheckBox
Android里面的单选框和html中的其实是一样的效果.这里用到两个控件:CheckBox和RadioGroup.直接上代码: radio.xml布局文件: <?xml version=&qu ...
- 可分组的选择框控件(MVVM下)(Toggle样式 仿造单选框RadioButton,复选框CheckBox功能)
原地址: http://www.cnblogs.com/yk250/p/5660340.html 效果图如下:支持分组的单选框,复选框样式和MVVM下功能的实现.这是项目中一个快捷键功能的扩展. 1, ...
- WPF中单选框RadioButton
单选框RadioButton的基本使用: <StackPanel Margin="10"> <Label FontWeight="Bold"& ...
- vue之v-for遍历下拉框select和单选框组radio-group
1.v-for遍历下拉框 <el-form-item label="审核状态:" prop="status"> <el-select v-mo ...
- Android入门(八):使用RadioGroup 和RadioButton组件建立单选清单
这一章,我们学习RadioGroup 和RadioButton组件,我们新建一个项目,编码过程与前几章的项目类似. 1.建立字符串资源文件strings.xml: <resources> ...
随机推荐
- C语言字符篇(四)字符串查找函数
#include <string.h> char *strchr(const char *s, int c); The strchr() function returns a ...
- poj 2965 枚举+DFS
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25343 ...
- Pandas 文本数据
Pandas针对字符串配备的一套方法,使其易于对数组的每个元素(字符串)进行操作. 1.通过str访问,且自动排除丢失/ NA值 # 通过str访问,且自动排除丢失/ NA值 s = pd.Serie ...
- 4、spring boot 配置文件之profile
Profile 1.多Profile文件 我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml 默认使用application.prop ...
- 17-比赛1 A - Weak in the Middle (栈)
题目描述 给定长度为 N 的序列 A.每天,序列 A 中所有比两侧元素都小的元素都会消失.对于原序列中所有元素,请求出它会在第几天之后消失(天数从 1 开始计算),或者指出它不会消失. 数据范围 1 ...
- Linux命令、权限
一.新建用户natasha,uid为1000,gid为555,备注信息为“master”: groupadd -g 555 natasha useradd -u 1000 -g 555 -c mast ...
- 发送广播重新挂载SD卡,使图库可以及时显示自己保存的图片(无需手机重启)
我们或许经常会遇到这种情况,明明保存了图片,但是当你打开图片时,却没有找到这张图片,手机重启之后才能看到.这是因为SD卡并没有重新挂载,图库也无法把这张图片加载进去,解决这个问题非常简单,只需要我们模 ...
- ARC下还会存在内存泄露吗?
1.第三方框架不正当使用.2.block,delegate,NSTimer循环使用.3.非oc对象的内存处理.4.地图类处理.5.大次数循环内存暴涨. 非oc对象的释放: 例如使用CGImageRel ...
- 《数据结构与算法分析:C语言描述》复习——第八章“并查集”——并查集
2014.06.18 14:16 简介: “并查集”,英文名为“union-find set”,从名字就能看出来它支持合并与查找功能.另外还有一个名字叫“disjoint set”,中文名叫不相交集合 ...
- php jsonp单引号转义
php中jsonp输出时一般用下面的格式: callbackname('json string'); 如果中间的json string中含有单引号,这个输出就是有问题的,调用方一般是无法处理的,所以我 ...