특정조건에 따라서 라디오버튼의 디폴트값을 설정해주려고 합니다.
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radio_group);
radioGroup.setOnCheckedChangeListener(this);
if(조건1)
radioGroup.check(R.id.radioButton1);
else if(조건2)
radioGroup.check(R.id.radioButton2);
else(조건3)
radioGroup.check(R.id.radioButton3);
이런식으로 했는데 실행하면 조건구문에서 오류가 납니다. 그래서 구글에서 검색해보다가
RadioButton rad1 = (RadioButton)findViewById(R.id.radioButton1);
rad1.setId(1);
RadioButton rad2= (RadioButton)findViewById(R.id.radioButton2);
rad2.setId(2);
RadioButton rad3= (RadioButton)findViewById(R.id.radioButton3);
rad3.setId(3);
if(조건1)
radioGroup.check(1);
else if(조건2)
radioGroup.check(2);
else(조건3)
radioGroup.check(3);
이렇게 하니까 조건1,2,3에 따라서 디폴트값이 선택이 되긴하는데 onCheckedChanged()메소드가 동작을 하지를 않습니다. 처음방법으로 할때는 디폴트값 선택구문만 제외시키면 onCheckedChanged()메소드는 잘 동작 했었거든요.
public void onCheckedChanged(RadioGroup arg0, int arg1) {
switch(arg1){
case R.id.radioButton1:
............;
break;
case R.id.radioButton2:
.............;
break;
case R.id.radioButton3:
.............;
break;
}
}