andorid 单选与复选
activity_ui1.xml
<?xml version="1.0" encoding="utf-8"?>
<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:padding="10dp"
android:orientation="vertical"
tools:context="com.hanqi.application3.UIActivity1"
android:weightSum="1"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择Android的开发语言是什么"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rb"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C++"
android:id="@+id/rb1"
android:layout_marginRight="30dp"
android:checked="true"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:id="@+id/rb2"
android:layout_marginRight="30dp"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="JAVA"
android:id="@+id/rb3"
android:layout_marginRight="30dp"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C#"
android:id="@+id/rb4"
android:layout_marginRight="30dp"
/> </RadioGroup>
<TextView
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="宋体"
android:id="@+id/cb_st"
android:checked="true"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加粗"
android:id="@+id/cb_jc"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="斜体"
android:id="@+id/cb_xt"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下划线"
android:id="@+id/cb_xhx"
/> </LinearLayout>
UIActivity1.java
package com.hanqi.application3; import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast; import static android.widget.CompoundButton.*; public class UIActivity1 extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui1); RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rb); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { if (checkedId == R.id.rb3) {
Toast.makeText(UIActivity1.this, "选对了", Toast.LENGTH_SHORT).show();
}
RadioButton rb = (RadioButton) findViewById(checkedId); Toast.makeText(UIActivity1.this, rb.getText(), Toast.LENGTH_SHORT).show();
} }); CheckBox cb_st= (CheckBox)findViewById(R.id.cb_st);
cb_st.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
CheckBox cb_xt= (CheckBox)findViewById(R.id.cb_xt);
cb_xt.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
CheckBox cb_jc= (CheckBox)findViewById(R.id.cb_jc);
cb_jc.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
CheckBox cb_xhx= (CheckBox)findViewById(R.id.cb_xhx);
cb_xhx.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
} private class CBOnCheckChangeListenter implements OnCheckedChangeListener
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { CheckBox cb = (CheckBox)buttonView;
if (isChecked) {
Toast.makeText(UIActivity1.this, "选中了", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(UIActivity1.this, "取消了", Toast.LENGTH_SHORT).show();
}
}
}
}
andorid 单选与复选的更多相关文章
- 关于通过jq /js 实现验证单选框 复选框是否都有被选中
今天项目中遇到一个问题 就是要实现,单选框,复选框 同时都被选中才能进行下一步的问题,开始用js原生来写 怎么写都觉得不合适,通过for循环得出 复选框被选中的,在通过for循环得出单选框被选中的,问 ...
- Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用
Default.aspx 网页界面 <%@ Page Language="C#" AutoE ...
- Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用
Default.aspx 网页界面 <%@ Page Language="C#" AutoE ...
- php一些单选、复选框的默认选择方法(示例)
转载 http://www.php.cn/php-weizijiaocheng-360029.html 一. radio和checkbox及php select默认选择的实现代码 1.radio单选框 ...
- Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...
- iCheck获取单选和复选框的值和文本
//获取单选和复选框的值//parameters.type:"radio","checkbox"//parameters.name:input-name//pa ...
- [Swift通天遁地]二、表格表单-(17)制作在表单左侧添加单选和复选组件的表单行
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 在微信框架模块中,基于Vue&Element前端,通过动态构建投票选项,实现单选、复选的投票操作
最近把微信框架的前端改造一下,在原来基于Bootstrap框架基础上的微信后台管理,增加一套Vue&Element的前端,毕竟Vue的双向绑定开发起来也还是很方便的,而且Element本身也提 ...
- jquery模拟下拉框单选框复选Select,Checkbox,Radio
在项目中,你会发现设计稿中常常会有单选框,复选框,但都不是系统默认的样式,这就可以用jquery来模拟它们:如图所示,实现它们所需要的代码如下: 首先需要引入的代码: <link rel=&qu ...
随机推荐
- 学习JS的心路历程-参数的传递(下)
今天我们要来探讨JS到底是透过何种参数传递方式呢? 废话不多说,上示例!! 我们先声明原始型别和物件型别来看看两者是否会有不一样的差异: var myStr = 'Hola': var myObj = ...
- atrous convolution
atrous convolution 简而言之,带孔卷积: 来自:https://zhuanlan.zhihu.com/p/27470685 假设一个二维信号,每个位置对应的输出为和卷积核为,带孔卷积 ...
- 关于池化(pooling)理解!!!
网上看到一个池化的解释是: 为了描述大的图像,可以对不同位置的特征进行聚合统计,如计算平均值或者是最大值,即mean-pooling和max-pooling 我的想法是,图像做卷积以后,将图像信息(特 ...
- Python基础学习Day7 基础数据类型的扩展 集合 深浅copy
一.基础数据类型的扩展 1.1GBK ---> UTF - 8 # str --->bytes s1 = '太白' # 字符串是unicode编码 b1 = s1.encode('gbk' ...
- js高级-递归调用
函数调用自身 求1-100的和 var sum = 0; for(var i = 1; i<=100; i++){ sum += i } console.log(sum) //自己写的递归 va ...
- 03_java基础(八)之static关键字与代码块
20\21.static关键字 /** * static关键字 * 1.用static修饰后的方法,称为静态方法. * 2.静态的方法特点,可以使用 类名.方法名称 调用方法 * 3.静态方法只能调用 ...
- flex-direction
[flex-direction] The flex-direction CSS property specifies how flex items are placed in the flex con ...
- 无线渗透wep加密路由器
停掉网络服务 service network-manager stop 检查现在的环境适不适合使用airmon-ng airmon-ng check 杀死可能冲突的进程 开启网卡monitor模式 a ...
- 使用synchronized wait() notifyall() 实现简单的加减法同步 竞争抢答
import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.co ...
- Monkey 命令收集相关 --追加Monkey自动化测试开源工具
.1.环境配置 MONKEY测试使用的是ADB命令,因此只需要配置ADB环境即可. 2.测试准备与执行 在Monkey测试前,必须进行以下准备 Ø 手机屏幕超时设置为30分钟或者永不超时,防止手机进 ...