我需要在我的应用中使用RadioGroup。但我不能在活动中初始化它。这有什么问题?
答案 0 :(得分:0)
RadioGroup mRadioGroup = (RadioGroup) view.findViewById(R.id.amountcollecte_radiogroup);
mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int id = mRadioGroup.getCheckedRadioButtonId();
View radioButton = mRadioGroup.findViewById(id);
if (radioButton.getId() == R.id.amountcollected_yes_radioButton) {
} else if (radioButton.getId() == R.id.amountcollected_no_radioButton) {
}
}
});
<RadioButton
android:id="@+id/amountcollected_yes_radioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="@color/black"
android:checked="true"
android:gravity="center"
android:text="Yes"
android:textColor="@color/black"
android:textSize="@dimen/text_large" />
<RadioButton
android:id="@+id/amountcollected_no_radioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="@color/black"
android:gravity="center"
android:text="No"
android:textColor="@color/black"
android:textSize="@dimen/text_large" />
</RadioGroup>
希望这会对你有所帮助。