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> ...
随机推荐
- 【转载】Callable、FutureTask中阻塞超时返回的坑点
本文转载自:http://www.cnblogs.com/starcrm/p/5010863.html 案例1: package com.net.thread.future; import java. ...
- 手动完全卸载Office
1 当然出现安装错误,或是无法安装先考虑官方卸载工具卸载,运行后要是解决了问题是最好的.毕竟手动删除比较麻烦. 开始我们先停止 Office Source Engine 服务.以windows7为例子 ...
- UIView控件 概况
一.UIKit结构图 ------------------------------------------------------------------------------- @interfac ...
- mysql sum 为 0 的解决方法
使用SQL语句SUM函数的时候,默认查询没有值的情况下返回的是null,而实际可能我们要用的是返回0. 解决方法:SELECT SUM(count) FROM test_table 改成: SELEC ...
- Android面试收集录8 HandlerThread详解
1.前言 我们知道在Android系统中,我们执行完耗时操作都要另外开启子线程来执行,执行完线程以后线程会自动销毁. 想象一下如果我们在项目中经常要执行耗时操作,如果经常要开启线程,接着又销毁线程, ...
- Eclipse 创建 Java 接口---Eclipse教程第11课
打开新建 Java 接口向导 新建 Java 接口向导可以创建新的 Java 接口.打开向导的方式有: 点击 File 菜单并选择 New > Interface 在 Package Explo ...
- 2016年后web开发趋势是什么?
2016 年后 Web开发趋势是什么 来源:yafeilee.me 发布时间:2016-05-06 阅读次数:1378 3 近二年的进展 前端发展日新月异, 甚至有一句戏言: "每六星期 ...
- VSX-5 VSXMusic 编码听音乐
给VS写个扩展来听音乐的说法,缘来已久,这两天做了个初版,使用豆瓣FM,先发出来. 插件现在只做了VS2013的,别的版本有待下一步支持. 现在暂时只有一个Adornment(就是那个有封面的),一个 ...
- 《Cracking the Coding Interview》——第11章:排序和搜索——题目4
2014-03-21 21:28 题目:给定一个20GB大小的文本文件,每一行都是一个字符串.请设计方法将这个文件里的字符串排序. 解法:请看下面的注释. 代码: // 11.4 Given a fi ...
- iOS-QQ好友列表实现
0.QQ好友列表实现 0.首先说说实现思路 自定义UITableView,每一个分组都是一个UITableViewHeaderFooterView,然后自定义cell,这里分组的实现主要是自定义UIT ...