实现多行RadioGroup
2014-08-12 17:26
211 查看
Android中的RadioGroup只能横向或者纵向单行摆放。实现多行RadioGroup实际上是使用了多个RadioGroup,而同时只能有一个RadioGroup起作用。
原文地址:http://www.tutorialforandroid.com/2009/11/select-radiobutton-from-multiple.html
Select a RadioButton from Multiple RadioGroup in Android
I bounds into Radiogroup
layout question while trying out something in android. The problem is that you want a RadioButton but you don't
want it to just be either horizontally placed or vertically placed which is the default way RadioGroup does. Say you want 2 rows of 4 RadioButton, by default you cant do this with one RadioGroup, so the solution is to make 2 RadioGroup but the problem now
is that you need to handle both RadioGroup in turn that when one RadioButton is selected on one RadioGroup the other RadioGroup/s will deselect itself. To do this here is the code on how i did it (it has 3 RadioGroups), it might not be the best solution :)
Explanation
Create a flag stating that we mark as whether the function could be execute or not (see below)
private Boolean changeGroup = false;
On the default change function of RadioGroup, create a conditional statement that would execute the change function
of all RadioGroup only when our flag state that it can execute the next code block. By default this function will execute when you select a RadioButton on a Group and/or when you call clearCheck() of each RadioGroup, and you may not want to do that especially
when we call clearCheck.
if (group != null && checkedId > -1 && changeGroup == false){
The following code will just set the flag to true when users select a RadioButton on any group, thus when other
RadioGroup call clearCheck() the code block in the function will not be called.
.....
原文地址:http://www.tutorialforandroid.com/2009/11/select-radiobutton-from-multiple.html
Select a RadioButton from Multiple RadioGroup in Android
I bounds into Radiogroup
layout question while trying out something in android. The problem is that you want a RadioButton but you don't
want it to just be either horizontally placed or vertically placed which is the default way RadioGroup does. Say you want 2 rows of 4 RadioButton, by default you cant do this with one RadioGroup, so the solution is to make 2 RadioGroup but the problem now
is that you need to handle both RadioGroup in turn that when one RadioButton is selected on one RadioGroup the other RadioGroup/s will deselect itself. To do this here is the code on how i did it (it has 3 RadioGroups), it might not be the best solution :)
private Boolean changeGroup = false; public void onCheckedChanged(RadioGroup group, int checkedId){ if (group != null && checkedId > -1 && changeGroup == false){ if(group == frequencyGroup1){ changeGroup = true; frequencyGroup2.clearCheck(); frequencyGroup3.clearCheck(); changeGroup = false; }else if(group == frequencyGroup2){ changeGroup = true; frequencyGroup1.clearCheck(); frequencyGroup3.clearCheck(); changeGroup = false; }else if(group == frequencyGroup3){ changeGroup = true; frequencyGroup1.clearCheck(); frequencyGroup2.clearCheck(); changeGroup = false; } } }
Explanation
Create a flag stating that we mark as whether the function could be execute or not (see below)
private Boolean changeGroup = false;
On the default change function of RadioGroup, create a conditional statement that would execute the change function
of all RadioGroup only when our flag state that it can execute the next code block. By default this function will execute when you select a RadioButton on a Group and/or when you call clearCheck() of each RadioGroup, and you may not want to do that especially
when we call clearCheck.
if (group != null && checkedId > -1 && changeGroup == false){
The following code will just set the flag to true when users select a RadioButton on any group, thus when other
RadioGroup call clearCheck() the code block in the function will not be called.
.....
相关文章推荐
- Android 自定义View实现多行RadioGroup单选(多选)
- Android 自定义View之RadioGroup实现跨多行显示
- Android 自定义View实现多行RadioGroup (MultiLineRadioGroup)
- 实现radiogroup的多行多列显示,行列自己定义
- RadioGroup实现单选框的多行排列
- Android 自定义View实现多行RadioGroup (MultiLineRadioGroup)
- RadioGroup+RadioButton嵌套其他布局实现多行单选布局、自定义RadioButton选中和非选中样式、文字颜色
- RadioGroup实现多行多列 不重写RadioGroup
- 自定义RadioGroup实现多行排列
- android自定义RadioGroup可以添加多种布局的实现方法
- RadioGroup控件实现单选题效果
- RadioGroup的多行布局
- Android开发Tabhost+RadioGroup实现底部菜单栏
- android自定义RadioGroup实现可以添加多种布局
- 巧妙实现缺角radiogroup控制多个fragment切换和滑动
- 使用 RadioGroup+TabHost 搭建框架实现 导航 切换
- 自定义RadioGroup实现单选完整示例
- RadioGroup中的RadioButton实现换行
- android自定义RadioGroup实现可以添加多种布局
- 实现RadioGroup控件使用,单选框。