Android中RadioGroup的初始化和简单的使用
一简介:
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的初始化和简单的使用的更多相关文章
- Android中NDK的搭建及简单使用 Android.mk相关介绍 JNI的使用
Android中NDK的搭建及简单使用: 使用NDK,简述其重要步骤:.搭建NDK环境(作用:用于自动生成jni下的.c对应的so文件)---到Android NDK官网或Android官网下载ndk ...
- Android中两个Activity之间简单通信
在Android中,一个界面被称为一个activity,在两个界面之间通信,采用的是使用一个中间传话者(即Intent类)的模式,而不是直接通信. 下面演示如何实现两个activity之间的通信. 信 ...
- 在Android中使App高速、简单地支持新浪微博、微信、QQ、facebook等十几个主流社交平台的分享功能
前言 在如今的APP或者游戏中,分享功能差点儿已经成为标配.分享功能不但能够满足用户的需求.也能够为产品带来很多其它的用户,甚至能够对用户的行为.活跃度.年龄段等情况进行数据统计,使得软件公司能够对产 ...
- android中TimePicker和DatePicker的简单使用
package com.example.demo10; import java.util.Calendar; import android.support.v7.app.ActionBarActivi ...
- Android中XML格式数据的简单使用
源码: package com.wangzhu.demo; import java.io.IOException; import java.io.StringWriter; import javax. ...
- android中ListView控件最简单的用法
创建一个活动,在xml文件中添加一个ListView控件,id定义为list1,并且设置为满屏显示,代码如下: <ListView android:id="@+id/list1&quo ...
- Android 中的菜单 OptionsMenu的简单应用
OptionsMenu就是安卓手机中的菜单选项 首先 要实现对菜单的操作就要先重写OnCreateOptionsMenu(Menu menu)方法 通常有两种方法来实现对菜单中选项的添加 第一种是动态 ...
- Android中ListView嵌套GridView的简单消息流UI(解决宽高问题)
最近搞一个项目,需要用到类似于新浪微博的消息流,即每一项有文字.有九宫格图片,因此这就涉及到ListView或者ScrollView嵌套GridView的问题.其中GridView的高度问题在网上都很 ...
- Android 中HttpURLConnection与HttpClient的简单使用
1:HttpHelper.java public class HttpHelper { //1:标准的Java接口 public static String getStringFromNet1(Str ...
随机推荐
- centos7.6设置sftp服务
sftp是Secure File Transfer Protocol的缩写,安全文件传送协议. CentOS自带 SSH 服务,直接配置即可 1. 查看ssh版本 sftp是基于ssh协议的,首先查看 ...
- RSA加密解密算法
/** * RSA加密解密算法 * Class Rsa */ class Rsa { /** * 获取pem格式的公钥 * @param $public_key 公钥文件路径或者字符串 * @retu ...
- Elastichsearch实践——基本使用
官网文档:https://www.elastic.co/guide/cn/elasticsearch/guide/current/getting-started.html es中的索引.类型.文档可以 ...
- 1、js的基本对象和垃圾回收
js常用的基本类型:Undefined,null,string,number,boolen 还有一种复杂的数据类型 object.判断类型可以用 typeof. 确定值是否是有穷的,isFinite, ...
- js数据结构与算法——字典与散列表
<script> //创建字典 function Dictionary(){ var items = {}; this.set = function(key,value){ //向字典添加 ...
- Useful Git Commands for me
查看Git追踪的文件 git ls-files 移除远程仓库的文件夹 git rm -r --cached some-directory git commit -m "Remove th ...
- FreeBSD 与中文
$ setenv LC_ALL en_US.UTF- 然后用 locale 检查 en_US 不是重点,重点是 UTF-8 . 然后用 putty,原因是默认终端又没有中文字体...然后就能输入输出中 ...
- eclipse 开发环境问题
1.jdk安装,环境变量设置.主要有两个: JAVA_HOME C:\Program Files\Java\jre7 JRE_HOME C:\Program Files\Java\jre7 2 ...
- win10 安装mysql8
参考:https://www.jb51.net/article/139219.htm mysql下载地址:https://dev.mysql.com/downloads/mysql/ 1.下载:mys ...
- ArcMap中获取要素的Extent值
新建xmax,xmin,ymax,ymin4个字段,右键,在[字段计算器]中选择Python,分别输入!shape.extent.XMax!.!shape.extent.XMin!.!shape.ex ...