2012-02-21 18 views

答えて

51

本当のトリックはループにあると呼んで、それはこのようなsetEnabled(boolean)

何かがトリックを行う必要があります。

//initialize the controls 
final RadioGroup rg1 = (RadioGroup)findViewById(R.id.radioGroup1); 
CheckBox ck1 = (CheckBox)findViewById(R.id.checkBox1); 

//set setOnCheckedChangeListener() 
ck1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 

    @Override 
    public void onCheckedChanged(CompoundButton checkBox, boolean checked) { 
     //basically, since we will set enabled state to whatever state the checkbox is 
     //therefore, we will only have to setEnabled(checked) 
     for(int i = 0; i < rg1.getChildCount(); i++){ 
      ((RadioButton)rg1.getChildAt(i)).setEnabled(checked); 
     } 
    } 
}); 

//set default to false 
for(int i = 0; i < rg1.getChildCount(); i++){ 
    ((RadioButton)rg1.getChildAt(i)).setEnabled(false); 
} 
RADIOGROUPが直接無効にすることはできません
+0

私がやった「汚れたハック」は実際のやり方であるようです。 :D – WORMSS

0

CheckBoxでonCheckedChangeListenerを使用し、setEnabledをRadioGroupで使用することができます。

幸運を祈り、 ティム

+4

radiogroup.setEnabled(true); does not work – Elchin

+3

申し訳ありませんが、これはRadioGroupでは機能しません。それは伝わっていないようです。 – WORMSS

-1

は、チェックボックスの状態に応じて処置を取り、それに応じてradiogroupのを設定します。 radiogroupというラジオグループがあると仮定すると、radiogroupを有効または無効にすることができます。

radiogroup.setEnabled(true);

チェックボックスにOnCheckedChangeListener()を追加します。すべての子どもたちが(この場合は:CheckBox)ビューを介して

+4

radiogroup.setEnabled(true); does not work – Elchin

+2

個々のRadioButton項目を無効にする必要があります。 –

0

、ラジオボタンをループして、それをfalseとして有効にする必要があります。

関連する問題