Android开发(20)--RadioGroup的使用
RadioGroup 有时候比較实用.主要特征是给用户提供多选一机制。
MainActivity.java
package com.example.lesson16_radio; import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast; public class MainActivity extends Activity {
private RadioGroup group_temo;
private RadioButton checkRadioButton; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
group_temo = (RadioGroup) findViewById(R.id.radioGroup1);
// 改变默认选项
group_temo.check(R.id.radio1); // 获取默认被被选中值 checkRadioButton = (RadioButton) group_temo.findViewById(group_temo
.getCheckedRadioButtonId()); Toast.makeText(this, "默认的选项的值是:" + checkRadioButton.getText(),
Toast.LENGTH_LONG).show(); // 注冊事件
group_temo
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { // 点击事件获取的选择对象
checkRadioButton = (RadioButton) group_temo
.findViewById(checkedId); Toast.makeText(getApplicationContext(),
"获取的ID是" + checkRadioButton.getText(),
Toast.LENGTH_LONG).show();
}
});
} }
布局文件
<RelativeLayout 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: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:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" > <RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/text_java" /> <RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_net" /> <RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_php" />
</RadioGroup> </RelativeLayout>
Android开发(20)--RadioGroup的使用的更多相关文章
- 【转】Android开发20——单个监听器监听多个按钮点击事件
原文网址:http://woshixy.blog.51cto.com/5637578/1093936 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律 ...
- android应用开发--------------看RadioGroup源代码,写相似单选选项卡的集成控件(如底部导航,tab等等)
博客为 有时个哥 原创.如需转载请标明出处:http://blog.csdn.net/ls703/article/details/46694967 watermark/2/text/aHR0cDovL ...
- Android开发之程序猿必需要懂得Android的重要设计理念2(5.20更新版)
上篇文章介绍了Android开发的设计理念的一部分,并没有得到博友们的多大认可,仅仅看到了一位博友在以下留言期待下一篇文章的发表,为了这小小的唯一支持.我决定继续把后面的8个要点介绍一下,自己也潜心反 ...
- Android开发-之认识palette
Android开发中,Google工程师已经给我们封装好了很多的按钮,使得我们在开发中非常的方便和便捷. 那么今天就来认识一下常用的按钮,那么在之前的课程中我已经详细讲过了Button按钮,那么这里就 ...
- 【Android学习】《Android开发视频教程》第一季笔记
视频地址: http://study.163.com/course/courseMain.htm?courseId=207001 课时5 Activity基础概念 1.Android开发技术结构 ...
- Android开发学习之路--数据持久化之初体验
上班第一天,虽然工作上处于酱油模式,但是学习上依旧不能拉下,接着学习android开发吧,这里学习数据持久化的 知识. 其实数据持久化就是数据可以保存起来,一般我们保存数据都是以文件,或者数据库的形式 ...
- Android开发 ---xml布局元素
1.android:orientation="vertical/horizontal" vertical为垂直布局, horizontal为水平布局 2.android:layou ...
- Android开发之自定义的ListView(UITableViewController)
Android开发中的ListView, 顾名方法思义,就是表视图.表示图在iOS开发中就是TableView.两者虽然名称不一样,但是其使用方法,使用场景以及该控件的功能都极为相似,都是用来展示大量 ...
- Android开发用过的十大框架
http://blog.csdn.net/u011200604/article/details/51695096 本文系多方综合与转载整合,意在Android开发中能够知道和使用一些好用的第三方支持, ...
- [译]:Xamarin.Android开发入门——Hello,Android快速上手
返回索引目录 原文链接:Hello, Android_Quickstart. 译文链接:Xamarin.Android开发入门--Hello,Android快速上手 本部分介绍利用Xamarin开发A ...
随机推荐
- 正则表达式JSP实例
<%@ page language="java" import="java.util.*,cn.com.Person,cn.com.Adddress" p ...
- POJ 1386 有向图欧拉通路
题意:给你一些字符串,这些字符串可以首位相接(末位置如果和另一个字符串的首位置相同的话就可以相连) .然后问你是否可以全部连起来. 思路:就是取出每个字符串的首尾位置,然后求出出度和入度,根据有向欧拉 ...
- JavaScript中函数参数的按值传递与按引用传递(即按地址传递)
首先声明一句:JavaScript中所有函数的参数都是按值传递的!不存在按引用传递! 在讲传递参数之前我们先来讲一下指针. 学过C指针的应该都知道,指针变量中保存的是一个地址,程序可以根据所保存的地址 ...
- SQL自连接(源于推荐算法中的反查表问题)
”基于用户的协同过滤算法“是推荐算法的一种,这类算法强调的是:把和你有相似爱好的其他的用户的物品推荐给你. 要实现该推荐算法,就需要计算和你有交集的用户,这就要用到物品到用户的反查表. 先举个例子说明 ...
- Xcode7国际化(根据系统语言切换App显示的语言) - 元宵节快乐!
老规矩, 上gif 下面是配置的大概流程: 这个是要显示中文的.strings文件的内容和格式 这个是要显示英文的.strings文件的内容和格式 下面是应用名部分: 然后下面是代码部分: impor ...
- MySQL 大DML操作建议
㈠ 大数据量INSERT ⑴ 使用多行插入代替单行:insert into t values (),(),(),... ⑵ LOAD DATA INFILE ... ...
- 对于js原型和原型链继承的简单理解(第一种,原型链继承)
原型是js中的难点加重点,也是前端面试官最爱问的问题之一,因为面试官可以通过被面试者对原型的理解.来判断被面试者对js的熟悉程度. 原型的定义 Js所有的函数都有一个prototype属性,这个属性引 ...
- DeDe调用指定栏目ID下的文章
*注: row: 调用条数 titlelen: 字数 typeid: 调用的栏目ID orderby: 按照升序对记录进行排序 idlist: 提取特定文档为空 infolen='40' 内容简介长度 ...
- centos卸载自带的apache(httpd)
.[root@localhost etc]# rpm -qa|grep httpd,查看与httpd相关软件包. httpd--.el5_2.CentOS. .然后删除httpd: [root@loc ...
- python学习第十天 -- 函数
稍微学过其他编程语言的人都应该了解函数的概念.在这里就不做过多的介绍. Python内置了很多有用的函数,我们可以也直接调用. 可以直接从Python的官方网站查看文档: http://docs.py ...