一简介:

RadioGroup作为一个单选按钮组,可以设置为性别选择男或则女,地址选择等等,作为一个android入门级选手,就简单的说一下RadioGroup组中RadioButton的布局和初始化操作,以及禁用整个RadioGroup。

二具体介绍:

布局:

  <RadioGroup
android:id="@+id/rg_Orientation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"> <RadioButton
android:id="@+id/rb_Portrait"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:drawableRight="@drawable/r_portrait" /> <RadioButton
android:id="@+id/rb_Landscape"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/r_landscape"/>
</RadioGroup>

初始化:

 radioGroup_orientation = (RadioGroup) findViewById(R.id.rg_Orientation);

给初始化完成的RadioGroup设置监听

radioGroup_orientation.setOnCheckedChangeListener(radioGrouplisten);

监听的具体逻辑

//RadioGroup控件的初始化
private RadioGroup.OnCheckedChangeListener radioGrouplisten = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) { int id = group.getCheckedRadioButtonId();
switch (group.getCheckedRadioButtonId()) {
case R.id.rb_Landscape:
orientation = Orientation.landscape;
Log.i("orientation",orientation.toString());
//Toast.makeText(PrintSettingActivity.this, orientation.toString(), Toast.LENGTH_SHORT).show();
break;
case R.id.rb_Portrait:
orientation = Orientation.Portrait;
Log.i("orientation",orientation.toString());
//Toast.makeText(PrintSettingActivity.this, orientation.toString(), Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
};

RadioGroup的所有单选按钮均不可点击,需要遍历RadioGroup中的每一个单选按钮,可以根据限定条件来对按钮进行控制

 public void disableRadioGroup(RadioGroup radioGroup,String fileName){
if(recPath.endsWith("pdf")){
for (int i = 0; i < radioGroup.getChildCount(); i++) {
radioGroup.getChildAt(i).setEnabled(false);
}
}
}

三总结:

  

  

Android中RadioGroup的初始化和简单的使用的更多相关文章

  1. Android中NDK的搭建及简单使用 Android.mk相关介绍 JNI的使用

    Android中NDK的搭建及简单使用: 使用NDK,简述其重要步骤:.搭建NDK环境(作用:用于自动生成jni下的.c对应的so文件)---到Android NDK官网或Android官网下载ndk ...

  2. Android中两个Activity之间简单通信

    在Android中,一个界面被称为一个activity,在两个界面之间通信,采用的是使用一个中间传话者(即Intent类)的模式,而不是直接通信. 下面演示如何实现两个activity之间的通信. 信 ...

  3. 在Android中使App高速、简单地支持新浪微博、微信、QQ、facebook等十几个主流社交平台的分享功能

    前言 在如今的APP或者游戏中,分享功能差点儿已经成为标配.分享功能不但能够满足用户的需求.也能够为产品带来很多其它的用户,甚至能够对用户的行为.活跃度.年龄段等情况进行数据统计,使得软件公司能够对产 ...

  4. android中TimePicker和DatePicker的简单使用

    package com.example.demo10; import java.util.Calendar; import android.support.v7.app.ActionBarActivi ...

  5. Android中XML格式数据的简单使用

    源码: package com.wangzhu.demo; import java.io.IOException; import java.io.StringWriter; import javax. ...

  6. android中ListView控件最简单的用法

    创建一个活动,在xml文件中添加一个ListView控件,id定义为list1,并且设置为满屏显示,代码如下: <ListView android:id="@+id/list1&quo ...

  7. Android 中的菜单 OptionsMenu的简单应用

    OptionsMenu就是安卓手机中的菜单选项 首先 要实现对菜单的操作就要先重写OnCreateOptionsMenu(Menu menu)方法 通常有两种方法来实现对菜单中选项的添加 第一种是动态 ...

  8. Android中ListView嵌套GridView的简单消息流UI(解决宽高问题)

    最近搞一个项目,需要用到类似于新浪微博的消息流,即每一项有文字.有九宫格图片,因此这就涉及到ListView或者ScrollView嵌套GridView的问题.其中GridView的高度问题在网上都很 ...

  9. Android 中HttpURLConnection与HttpClient的简单使用

    1:HttpHelper.java public class HttpHelper { //1:标准的Java接口 public static String getStringFromNet1(Str ...

随机推荐

  1. hihocoder 1505

    hihocoder 1505 题意:给你n个数,让你从n个数中抽两个数,再抽两个数,使得前两个数和后两个数相等 分析:对 i,j,p,q遍历的话时间复杂度会达到o(n4),所以考虑优化p,q 假设分配 ...

  2. django+vue

    django安装配置方式略过 1.安装node.js,官网地址:https://nodejs.org/zh-cn/download/ 2.cd到项目目录下,执行npm install -g vue-c ...

  3. tar解压指定文件

    import tarfileimport sys#tar = tarfile.open('/opt/platform-omp/omp.tar.gz','r')tar = tarfile.open(r' ...

  4. QT学习之解决QT中QIcon图标不显示的问题

    第一种:图标存放目录问题 :/文件夹名称/文件名 如:文件夹为:/img   文件名为:a.png 路径:     :/img/a.png 这里注意前面的":". 第二种:编译生成 ...

  5. python正则表达式基础,以及pattern.match(),re.match(),pattern.search(),re.search()方法的使用和区别

    正则表达式(regular expression)是一个特殊的字符序列,描述了一种字符串匹配的模式,可以用来检查一个字符串是否含有某种子字符串. 将匹配的子字符串替换或者从某个字符串中取出符合某个条件 ...

  6. Assets.car 解压工具 cartool 使用报错 segmentation fault cartool 解决方案

    1  cartool 下载地址 https://github.com/steventroughtonsmith/cartool 由于在macOS Mojave系统上 之前代码会报错需要修改main.m ...

  7. boostrap日期时间插件datetimepicker使用过程的一些问题总结

    1.汉化问题 虽然有转门的汉化脚本,不过如果简单使用的话自己稍微改一下源码就行了: var dates = $.fn.datetimepicker.dates = { en: { days: ['Su ...

  8. canal-随记001-吐血一个下午找bug

    前天leader说,阿里的新版本canal支持 canal收集binlog直接发到kafka,你要不研究一下? ok,没问题. 昨天周六,在家搭了套环境.解决centos7安装mysql各种小细节,按 ...

  9. angular6、7 兼容ie9、10、11

    1. 找到 polyfill.ts 并打开注释 /** * This file includes polyfills needed by Angular and is loaded before th ...

  10. Python 实现整数线性规划:分枝定界法(Branch and Bound)

    今天做作业,要实现整数线性规划的分枝定界法算法.找了一些网上的博客,发现都很屎,感觉自己写的这个比较清楚.规范,所以在此记录.如有错误,请指正. from scipy.optimize import ...