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.
.....
Hope i could explain it more clearly but its kinda hard :)
Update History
Jan 17, 2012 - Visual Update
1 comment:
[...] almondmendoza.com 标签: Android, Multiple, RadioButton, RadioGroup Share this post! Twitter Digg Facebook [...]
Post a Comment