В одном упражнении у меня есть DatePicker (счетчик), который позволяет пользователю выбрать дату своего рождения, ниже этого пользователя также должен выбрать свой пол. У меня есть кнопка, которая будет включена после того, как оба значения были установлены (дата и пол). Проблема, с которой я сталкиваюсь, - это включение этой кнопки, несмотря на то, какое значение изменяется первым. В настоящее время пользователь должен выбрать свою дату рождения, а затем свой пол для кнопки, чтобы активировать. Я бы хотел, чтобы кнопка была включена независимо от того, какие значения были изменены первыми.
Вот мой код:
final RadioGroup rGroup = findViewById(R.id.gender_radio_group);
RadioButton female_radio_button = rGroup.findViewById(rGroup.getCheckedRadioButtonId());
RadioButton male_radio_button = rGroup.findViewById(rGroup.getCheckedRadioButtonId());
RadioButton non_binary_radio_button = rGroup.findViewById(rGroup.getCheckedRadioButtonId());
//Check if datePicker and gender radiobutton has been used, if true enable button
calendar.setTimeInMillis(System.currentTimeMillis());
datePicker_birthday.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth) {
// This overrides the radiogroup onCheckListener
rGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// This will get the radiobutton that has changed in its check state
RadioButton checkedRadioButton = group.findViewById(checkedId);
// This puts the value (true/false) into the variable
boolean isChecked = checkedRadioButton.isChecked();
// If the radiobutton that has changed in check state is now checked...
if (isChecked) {
continue_register_birthday_gender_button.setEnabled(true);
continue_register_birthday_gender_button.setBackground(ContextCompat.getDrawable(RegisterBirthDateAndGenderActivity.this,
R.drawable.button_active));
}
}
});
}
});