2011-02-27 17 views
0

나는 만들고있는 응용 프로그램에 라디오 버튼이 있습니다. 사용자가 하나의 옵션을 클릭하면 다른 라디오 버튼을 클릭 해제 할 수 있기를 원합니다.클릭 리스너의 라디오 버튼

어떻게해야할지 모르겠다. 라디오 버튼은 onclick 수신기에서 설정되고 로직은 클릭 할 때 설정됩니다.

답변

3

나머지 버튼에는 setEnabled(false)을 부르는 것은 어떨까요? 당신이 배열에 넣어 고려할 수 있습니다 너무 많은 버튼이있는 경우 :

RadioButton[] buttons; //you put here all buttons.. 

// then, when you catch the click, call a method like this 
private void disableOtherButtons(RadioButton buttonClicked) 
    for(RadioButton button : buttons){ 
     if(button != buttonClicked){ 
      button.setEnabled(false); 
     } 
    } 
} 
0

경우 다음 예제 라디오 버튼 중 하나에,을 radioGroup을 사용하면 그룹에이를 수있는 XML을 사용하여 한 번에 선택할 수 있습니다.

<RadioGroup 
     android:id="@+id/rg_configup1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     > 
     <RadioButton 
      android:id="@+id/rb_configup1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Sales" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" 
      > 
     </RadioButton> 
     <RadioButton 
      android:id="@+id/rb_configup2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Regional" 
      android:layout_above="@+id/rb_configup1" 
      android:layout_alignLeft="@+id/rb_configup1" 
      > 
     </RadioButton> 
     <RadioButton 
      android:id="@+id/rb_configup3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Global" 
      android:layout_above="@+id/rb_configup2" 
      android:layout_alignLeft="@+id/rb_configup1" 
      > 
     </RadioButton> 
     <RadioButton 
      android:id="@+id/rb_configup4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Ad-hoc" 
      android:layout_above="@+id/rb_configup3" 
      android:layout_alignLeft="@+id/rb_configup1" 
      > 
     </RadioButton> 
    </RadioGroup>