<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hanqi.test5"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".UIActivity1">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LongClickActivityActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <activity android:name=".CalculatorActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity1" /> </application> </manifest>
package com.hanqi.test5;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast; public class UIActivity1 extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui1);
//单选框
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rg); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
if (checkedId == R.id.rb3) //rb3设定为正确答案
{
Toast.makeText(UIActivity1.this, "选对了", Toast.LENGTH_LONG).show();
}
RadioButton rb = (RadioButton) findViewById(checkedId);
Toast.makeText(UIActivity1.this, rb.getText(), Toast.LENGTH_LONG).show();
}
}); //复选框
CheckBox cb_st = (CheckBox)findViewById(R.id.cb_st);
cb_st.setOnCheckedChangeListener(new CBOnCheckedChangListenter() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { }
}); cb_st.setOnCheckedChangeListener(new CBOnCheckedChangListenter()); CheckBox cb_jc = (CheckBox)findViewById(R.id.cb_jc);
cb_jc.setOnCheckedChangeListener(new CBOnCheckedChangListenter()); CheckBox cb_xt = (CheckBox)findViewById(R.id.cb_xt);
cb_xt.setOnCheckedChangeListener(new CBOnCheckedChangListenter()); CheckBox cb_xhx = (CheckBox)findViewById(R.id.cb_xhx);
cb_xhx.setOnCheckedChangeListener(new CBOnCheckedChangListenter()); }
private class CBOnCheckedChangListenter implements CompoundButton.OnCheckedChangeListener
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
CheckBox cb = (CheckBox)buttonView; if (isChecked) {
Toast.makeText(UIActivity1.this, "选中了" + cb.getText(), Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(UIActivity1.this, "取消了" + cb.getText(), Toast.LENGTH_LONG).show();
}
}
}
}
<?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.test5.UIActivity1">
<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/rg"> <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" />
</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>

在虚拟机6.0版本实现时,自带动画效果很好,可以用于做调查或者考试

效果图:

Android课程---单选框与复选框的实现的更多相关文章

  1. Selenium3自动化测试【28】单选框、复选框、下拉选择框

    Html页面中的单选按钮.复选框.下拉框均可通过WebDriver实现操做.本节结合案例一起来看看WebDriver如何操做这些控件. 同步视频知识与系列知识内容,可关注:[公众号]:柒哥测试:[WX ...

  2. CSS学习笔记三:自定义单选框,复选框,开关

    一点一点学习CCS,这次学习了如何自定义单选框,复选框以及开关. 一.单选框 1.先写好body里面的样式,先写几个框 <body> <div class="radio-1 ...

  3. 自动化测试-15.selenium单选框与复选框状态判断

    本篇主要介绍单选框和复选框的操作 一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了 ...

  4. 2.12 单选框和复选框(radiobox、checkbox)

    2.12 单选框和复选框(radiobox.checkbox) 本篇主要介绍单选框和复选框的操作一.认识单选框和复选框    1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是 ...

  5. Selenium2学习(十五)-- 单选框和复选框(radiobox、checkbox)

    本篇主要介绍单选框和复选框的操作 一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了 ...

  6. 微信小程序-修改单选框和复选框大小的方法

    方法有两种: 一:采用css的zoom属性 zoom缩放会将元素保持在左上角,并且会有毛边,可能会稍稍改变元素原来的形状. 二:采用css3的transform:scale属性 zoom缩放会将元素保 ...

  7. HTML--使用单选框、复选框,让用户选择

    在使用表单设计调查表时,为了减少用户的操作,使用选择框是一个好主意,html中有两种选择框,即单选框和复选框,两者的区别是单选框中的选项用户只能选择一项,而复选框中用户可以任意选择多项,甚至全选.请看 ...

  8. Selenium3+python自动化 单选框和复选框

    一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了,可以先抽他了. 二.radio和 ...

  9. jQuery获取单选框(复选框)选中的状态

    jQuery 获取单选框(复选框)选中的状态 <input type="checkbox" name="" id="choose"/& ...

  10. vue.js实现单选框、复选框和下拉框

    Vue.js可以很方便的实现数据双向绑定,所以在处理表单,人机交互方面具有很大的优势.下边以单选框.复选框和下拉框为例介绍他们在HTML和Vue.js中的具体实现方式. 一.单选框   在传统的HTM ...

随机推荐

  1. Codeforces Round #354 (Div. 2)-A

    A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...

  2. css -- 导航条

    1.垂直导航条 HTML: <ul class="nav"> <li><a href="">Home</a>&l ...

  3. 关于window.showModalDialog的一些配置

    关于window.showModalDialog的一些配置 一.window.showModalDialog的滚动条 其实纵向滚动条很好去掉,难办的就是横向滚动条.在Firefox下如果window. ...

  4. web api :Routing in ASP.NET Web API

    引 Web API 和SignalR都是在服务层. If you are familiar with ASP.NET MVC, Web API routing is very similar to M ...

  5. storm进程正常运行一段时间shut down,运维方式

    storm启动一段时间后,无征兆的停止了,然后nimbus,supervisor,ui所有的worker都stop了. 我用的storm是0.8.2版本的 nimbus中留下的log如下 -- :: ...

  6. DOM的概念及子节点类型

    前言 DOM的作用是将网页转为一个javascript对象,从而可以使用javascript对网页进行各种操作(比如增删内容).浏览器会根据DOM模型,将HTML文档解析成一系列的节点,再由这些节点组 ...

  7. [深入浅出WP8.1(Runtime)]文本框(TextBox)

    4.4 文本框(TextBox) 文本框(TextBox)控件是表示一个可用于显示和编辑单格式.多行文本的控件.TextBox控件常用于在表单中编辑非格式化文本,例如,如果一个表单要求输入用户姓名.电 ...

  8. 为什么用evernote

    其实是没有什么为什么的. 如果真要找个理由,那应该是: 为知的界面看着总觉得很糙.      这个糙指的是不像个好软件,而装上evernote感觉就不一样. 有道笔记新版本貌似在我这儿有BUG.    ...

  9. mysql 存储过程,搞死人的语法

    MySQL 真心不如sqlserver灵活 存储过程注意事项: 1.declare 依次声明 DECLARE MyAccountID VARCHAR (36); DECLARE Balance DEC ...

  10. JavaScript放置位置区别

    JavaScript放置位置区别 页面中的脚本会在页面载入浏览器后立即执行.我们并不总希望这样.有时,我们希望当页面载入时执行脚本,而另外的时候,我们则希望当用户触发事件时才执行脚本. 位于 head ...