`
bcyy
  • 浏览: 1827908 次
文章分类
社区版块
存档分类
最新评论

Andriod游戏开发系统控件-RadioButton

 
阅读更多

Andriod游戏开发系统控件-RadioButton

RadioButton是单选按钮,和CheckButton一样都基础Button。RadioButton一般都存在单选组(RadioGroup)中,当多个RadioButton存放在一个单选组中,只能选一个RadioButton;如果想实现RadioButton的多选,那就需要多个RadioGroup。

创建项目:RadioButtonProject

作者:wwj

日期:2012/5/11

功能:实现单选按钮

项目运行效果图:

修改布局文件:

=>>main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 	<RadioGroup
    android:id="@+id/radGrp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <RadioButton
        android:id="@+id/rb1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/radB1"
        />
    <RadioButton
        android:id="@+id/rb2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/radB2"
        />
    <RadioButton
        android:id="@+id/rb3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/radB3"
        />
    </RadioGroup>
    </LinearLayout>


修改velue文件

=>>string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, RadioButtonActivity!</string>
    <string name="app_name">RadioButton</string>
    <string name="radB1">RadioButton1</string>
    <string name="radB2">RadioButton2</string>
    <string name="radB3">RadioButton3</string>

</resources>

修改Activity文件

=>>RadioButtonProject.java

package com.radioButton;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

public class RadioButtonActivity extends Activity implements OnCheckedChangeListener{
	private RadioButton rb1,rb2,rb3;
	private RadioGroup rg;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        rb1 = (RadioButton) findViewById(R.id.rb1);
        rb2 = (RadioButton) findViewById(R.id.rb2);
        rb3 = (RadioButton) findViewById(R.id.rb3);
        rg = (RadioGroup) findViewById(R.id.radGrp);
        rg.setOnCheckedChangeListener(this);//将单选组绑定监听器
    }
    //重写监听器函数
    public void onCheckedChanged(RadioGroup group, int checkedId) {
		if(group==rg){
			String rbName = null;
			if(checkedId == rb1.getId()){
				rbName = rb1.getText().toString();
			} else if (checkedId == rb2.getId()){
				rbName = rb2.getText().toString();
			} else if(checkedId == rb3.getId()){
				rbName = rb3.getText().toString();
			}
			Toast.makeText(this,"选择了下标为“"+ rbName + "”的单选按钮",
					Toast.LENGTH_LONG).show();
			
		}
		
	}   
}



分享到:
评论

相关推荐

    android开发揭秘PDF

    第1章 Android开发简介 1.1 Android基本概念 1.1.1 Android简介 1.1.2 Android的系统构架 1.1.3 Android应用程序框架 1.2 OMS介绍 1.2.1 OPhone介绍 1.2.2 Widget介绍 1.3 小结 第2章 Android开发环境搭建 2.1 ...

    新版Android开发教程.rar

    这一联盟将会支持 Google 发布的 Android 手机操作系统或者应用软件,共同开发名为 Android 的 开 放源代码的移动系统。开放手机联盟包括手机制造商、手机芯片厂商和移动运营商几类。目前,联盟成员 数 量已经达到了...

    Android应用开发揭秘pdf高清版

    第1章 Android开发简介 1.1 Android基本概念 1.1.1 Android简介 1.1.2 Android的系统构架 1.1.3 Android应用程序框架 1.2 OMS介绍 1.2.1 OPhone介绍 1.2.2 Widget介绍 1.3 小结 第2章 Android开发环境搭建 2.1 ...

    《Android应用开发揭秘》附带光盘代码.

     第1章 Android开发简介  1.1 Android基本概念  1.1.1 Android简介  1.1.2 Android的系统构架  1.1.3 Android应用程序框架  1.2 OMS介绍  1.2.1 OPhone介绍  1.2.2 Widget介绍  1.3 小结  第2章 Android...

    《Android应用开发揭秘》源码

     第1章 Android开发简介  1.1 Android基本概念  1.1.1 Android简介  1.1.2 Android的系统构架  1.1.3 Android应用程序框架  1.2 OMS介绍  1.2.1 OPhone介绍  1.2.2 Widget介绍  1.3 小结  第2章 Android...

    android RadioButton和CheckBox组件的使用方法

    本次实验中主要是学习如何使用RadioGroup,CheckBox,RadioButton和Toast这几个控件,android UI开发中也会经常用到他们

    演示Android通用控件包括TextView, EditText,AutoCompleteTextView等控件

    环境:Windows XP SP3, JDK 1.6, Android SKD 3.0, Eclipse galileo 3.4 使用步骤: 1、下载解压之后,使用IDE导入Android工程 2、创建AVD为Android 2.2版本,...目的:熟悉Android 2.2版本的常用控件,以方便开发。

    Android-XRadioGroup可以实现任意嵌套RadioButton

    XRadioGroup:可以实现任意嵌套RadioButton

    Android开发案例驱动教程 配套代码

    《Android开发案例驱动教程》 配套代码。 注: 由于第12,13,14章代码太大,无法上传到一个包中。 这三节代码会放到其他压缩包中。 作者:关东升,赵志荣 Java或C++程序员转变成为Android程序员 采用案例驱动模式...

    关于如何自定义Android开发控件Button样式Demo

    在安卓开发中,我们经常用到Button按钮这个空间,默认系统提供的Button按钮样式比较单调,不适合项目应用 * ,通常我们需要自定义Button样式,自定义Button样式有三种: * 1、使用.9格式图片作为Button背景,或者...

    Android核心技术与实例详解 PDF扫描版

    第1章 Android开发起步 1 1 Android平台简介 1 1 1 Android背景介绍 1 1 2 Android平台架构 1 2 Android开发环境的搭建 1 2 1 相关软件的下载与安装 1 2 2 虚拟设备的创建和使用 1 2 3 创建“Hello Android” 1 2 4 ...

    Android应用开发学习代码集合,基于AndroidStudio

    介绍 学习Android开发的代码,基于AndroidStudio View_Demo是Android基础控件和布局,包括TextView,Edittext,ImageView,Button,RadioButton,Checkbox,ProgressBar和拖动条。 Adapter_Demo 是Adapter相关的代码...

    老罗android视频开发源码和ppt经典

    1.3 如何搭建android开发环境 1.4 android生命周期的介绍 1.5 android使用全局变量传递数据 1.6 android使用剪切板传递数据 1.7 意图传递数据的第一种方式 1.8 android使用静态变量传递数据 1.9 意图返回结果 二、...

    Android 控件详细介绍.ppt

    android 开发常用到的控件 ,这里做了详细的解释. 文本控件 TextView EditText 按钮控件 Button ImageButton 状态开关按钮 ToggleButton 单选与复选按钮 CheckBox和RadioButton 图片控件 ImageView 时钟控件 ...

    Android应用程序开发实验内容.doc

    7、8班:2015.3.24 【实验目的和要求】 1、安装配置Android开发环境,创建HelloWorld应用程序 2、了解Android项目的基本文件目录结构 【实验内容和原理或涉及的知识点】 【过程】 实验二:控件与布局 【设课形式】 ...

    集成目前Android主流优秀第三方组件

    这是一个集成目前Android主流优秀第三方组件、优秀好用的自定义控件、实用工具类封装、以及一些APP共通模块(比如:版本更新、意见反馈、引导界面等等)的开发包,帮助程序员快速开发自己的APP 已集成第三方开源...

Global site tag (gtag.js) - Google Analytics