0
私は1つのXMLファイルに2つのラジオ・グループがあります。同じラジオで、今別のラジオグループのラジオボタンをオフにするにはどうすればいいですか?
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.btn_1:
break;
case R.id.R.id.btn_2:
break;
case R.id.R.id.btn_3:
break;
case R.id.R.id.btn_4:
break;
}
}
:私はonRadioButtonClicked()
メソッドを実装することで、クリックリスナーのラジオボタンを扱うことができる主な活動で
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:id="@+id/btn_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
</LinearLayout>
をラジオボタンがチェックされている場合はグループ化され、もう1つは自動的にチェックされません。だからここに私の問題:私は、ボタンがチェックされている場合、同じグループ内の他のボタンと他のグループのチェックを外したい。これは実行可能ですか?おかげさまで
これはきれいですが、どうすればbtn1、btn2、btn3、btn4の参照を取得できますか? –
btn1.setOnCheckedChangeListener() –
ラジオボタンにsetonCheckedChangeListenerを追加できます –