In a activity, there is a FragmentViewPager which contains 5 Fragments. 5 Fragments will be created at the same time when starting the activity. If the fragment that do setChecked() isn't the front page when app executes CheckBox setChecked(true), the UI of CheckBox is blank and the value of isChecked() is true.
I found that notifyViewAccessibilityStateChangedIfNeeded( AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);
in setChecked(boolean checked)
of android CompoundButton.java. Maybe it can not change the UI when a fragment in background. But How to solve it.
if (cls.getIf_allow_to_join().equals("是")) {
checkBox.setChecked(true);
} else if (cls.getIf_allow_to_join().equals("否")) {
checkBox.setChecked(false);
}
This is the setChecked() code of Fragment OnCreateView() in a AsyncTask. And if I set this Fragment as the currentItem when I start the activity, there is no this issue.
Please use AppCompatCheckBox
instead of CheckBox
.
Check android.support.v7.widget.AppCompatCheckBox
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.