radioGroup执行clearCheck会出现StackOverflowError错误

未改之前代码
class MyRadioGroupOnCheckedChangedListener implements
	OnCheckedChangeListener {
		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			switch (group.getId()) {
			case R.id.task_info_top_radiogroup:
				radioGroup2.clearCheck();
				break;
			case R.id.task_info_bottom_radiogroup:
				radioGroup1.clearCheck();
				break;
			default:
				break;
			}
		}
	}

看起来一点事情都没有,然后只执行直接报了StackOverflowError错误

修改后的代码

class MyRadioGroupOnCheckedChangedListener implements
			OnCheckedChangeListener {
		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			switch (group.getId()) {
			case R.id.task_info_top_radiogroup:
				radioGroup2.setOnCheckedChangeListener(null);
				radioGroup2.clearCheck();
				radioGroup2.setOnCheckedChangeListener(new MyRadioGroupOnCheckedChangedListener());
				break;
			case R.id.task_info_bottom_radiogroup:
				radioGroup1.setOnCheckedChangeListener(null);
				radioGroup1.clearCheck();
				radioGroup1.setOnCheckedChangeListener(new MyRadioGroupOnCheckedChangedListener());
				break;
			default:
				break;
			}
		}
	}

这样就ok了

你可能感兴趣的:(RadioGroup,clearCheck)