С моей точки зрения, чтобы определить, что флажок "щелкнут" и найти, если он установлен, или нет, можно использовать следующий код:
cb=(CheckBox)findViewById(R.id.chkBox1);
cb.setOnCheckedChangeListener(this);
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
cb.setText("This checkbox is: checked");
}
else {
cb.setText("This checkbox is: unchecked");
}
}
Однако я не могу разобраться в логике того, как это сделать для радиогруппы.
Вот xml для моей RadioGroup:
<RadioGroup android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio1" android:checked="true"
android:text="RadioButton1">
</RadioButton>
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio2" android:text="RadioButton2" android:checked="true">
</RadioButton>
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio3" android:text="RadioButton3">
</RadioButton>
</RadioGroup>
Вопрос: Нужно ли мне настраивать другого слушателя, или же слушатель уже там "регистрирует" эту группу?
Также, должен ли слушатель быть настроен на RadioGroup или RadioButton?