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 ...
随机推荐
- 在windows下安装php redis扩展
我在本地是phpstudy集成环境,但是没有redis扩展,需要自己安装 1.先看清楚自己的php配置,在安装对应的 php_redis.dll 和 php_igbinary.dll php_redi ...
- pycharm远程调试docker容器内程序
文章链接: https://blog.csdn.net/hanchaobiao/article/details/84069299 参考链接: https://blog.csdn.net/github_ ...
- C#发送带附件的邮件的代码
如下的代码是关于C#发送带附件的邮件的代码. MailMessage m = new MailMessage();m.Subject = "File attachment!";m. ...
- vertx的Actor模型实现
前言 note: Context 与 EventLoop 关系 : N ; 每次创建一个vericles或者multi instances 通过EventLoopGroup.next挑出一个Event ...
- 终极版:Mybatis整合Spring配置
第一部分:配置 Spring 框架 配置 SpringMVC 的步骤: 配置流程图: SpringMVC 配置 1. 导入包(那些包,基本包 5 个,1 个日志依赖包,2 个 webmvc 支持包) ...
- 卢卡斯定理——应用hdu4349
#include<bits/stdc++.h> using namespace std; int n; int main(){ while(cin>>n){ ; while(n ...
- elsticsearch在kibanna中的操作
#建立索引 PUT /es_note_tel{ "settings": { "number_of_shards": 1 }, "mappings&qu ...
- Nginx+IIS+asp.net mvc 实现负载均衡示例
一.Nginx官网 http://nginx.org/ 二.下载并安装Nginx 下载地址:http://nginx.org/en/download.html 启动Nginx,启动成功的话可以在任务管 ...
- Zabbix (四)用户管理
本文章主要介绍zabbix用户管理,包括用户增删改查.用户报警媒介管理.用户权限管理 安装完zabbix后,系统会自带两个用户,分别为:Admin和Guests 一.超级管理员 zabbix安装完成后 ...
- About The Order of The Declarations And Definition When Making a Member Function a Friend.关于使类成员成为另一个类友元函数的声明顺序和定义。
If only member function clear of WindowMgr is a friend of Screen, there are some points need to note ...