Android RadioGroup及RadioButton的使用方法
2015-12-02 10:23
731 查看
效果图:
1、RadioGroup的布局文件
背景选择器:名称为top_button_selector.xml文件
字体选择器:名称为top_text_selector.xml文件
2、在Activity中设置监听器,并进行相应的操作
1、RadioGroup的布局文件
<RadioGroup android:id="@+id/rg" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_below="@+id/ll_title" android:layout_centerHorizontal="true" android:layout_marginBottom="15dp" android:layout_marginTop="5dp" android:orientation="horizontal" > <RadioButton android:id="@+id/rb_1" android:layout_width="95dp" android:layout_height="match_parent" android:background="@drawable/top_button_selector" android:button="@null" android:checked="true" android:gravity="center" android:text="待办" android:textColor="@drawable/top_text_selector" android:textSize="14dp" /> <RadioButton android:id="@+id/rb_2" android:layout_width="95dp" android:layout_height="match_parent" android:background="@drawable/top_button_selector_1" android:button="@null" android:gravity="center" android:text="已办" android:textColor="@drawable/top_text_selector" android:textSize="14dp" /> </RadioGroup>
背景选择器:名称为top_button_selector.xml文件
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/top_tab_01_bg_hover" android:state_checked="true"></item> <item android:drawable="@drawable/top_tab_02_bg" android:state_checked="false"></item> </selector>
字体选择器:名称为top_text_selector.xml文件
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/white" android:state_checked="true"></item> <item android:color="@color/gray_text" android:state_checked="false"></item> </selector>
2、在Activity中设置监听器,并进行相应的操作
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub switch (checkedId) { case R.id.rb_1: mCurrentType = "undone"; gdAdapter.addData(notDealgongDanInfoArr, mCurrentType); gdAdapter.notifyDataSetChanged(); break; case R.id.rb_2: mCurrentType = "done"; gdAdapter.addData(dealgongDanInfoArr, mCurrentType); gdAdapter.notifyDataSetChanged(); break; default: break; } } });
相关文章推荐
- Android大神
- Android开源框架Universal-Image-Loader详解
- 015ListView与SimperAdapter
- android杀掉指定包名的应用程序
- android 音频底层调试-tinyalsa
- android 从相册中获取图片设置成头像的问题:
- 安卓初学-自定义View(Creating a View Class)
- AndroidIO补充
- 深入分析android中的Cursor 对象是如何获得的
- android 长按弹出菜单,复制,粘贴,全选
- Debugging Android JNI with CheckJNI
- Android编程实现在Bitmap上涂鸦效果
- Android中的线程通信
- 分享方法:android 获得屏幕状态
- android之间传递list
- Android学习资料
- Android系统init.rc分析
- Android四大布局及其主要属性
- Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class lzl.edu.c
- Android编程实现监控各个程序流量的方法