我知道这听起来很奇怪所以这是图片。
它拥有正确的值(value)。 (部分)选择了正确的单选按钮。 OnCheckedChangeListener
中的所有逻辑都已正确执行。我完全惊呆了。为什么单选按钮未完全选中?
我唯一能想到的是我正在使用 Rx2Firebase
periodRetriever = FirebaseHelper.getInstance(getContext()).getPeriod()
.defaultIfEmpty(0)
.distinctUntilChanged()
.subscribe(new Consumer<Integer>() {
@Override
public void accept(@NonNull Integer headerType) throws Exception {
getRadioViewChecked(headerType).setChecked(true);
}
});
编辑1
EDIT2
布局:
<RadioGroup
android:id="@+id/rgPeriod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rbMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/month" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rbWeek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/week" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rb4Weeks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/four_weeks" />
</RadioGroup>
最佳答案
看起来像一个动画错误。在 ViewPager 内的 Fragment 上使用 CompoundButton 时,可绘制状态设置不正确。
这也发生在复选框中,如下所示:Android Nougat: Why do checkboxes on Fragment have incomplete state when selected programmatically (but look fine on Lollipop) .
在调用 RadioGroup.check(id) 或 Checkbox.setChecked(true) 之后调用 jumpDrawablesToCurrentState() 似乎可以解决问题(thx @Dalmas)
关于android - 单选按钮仅被部分选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45926301/