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