Насколько я понимаю, чтобы определить, установлен ли флажок, и выяснить, отмечен он или нет, можно использовать следующий код:
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?