Skip to content

Commit ca13b15

Browse files
author
Yu Haonong
committed
Switch widget: Fix ON/OFF option update error
When calling setChecked() from a listener which is invoked by the Switch toggle, setChecked() will be called recursively, causing the value of mThumbPosition overridden by the outer setChecked(). This make the nested setChecked() unable to update the "Thumb" position correctly. Set mThumbPosition to sync up with the exact checked state of the Switch to avoid update error. Issue 34748 Change-Id: Id4aa389114dcc590430b11626c80d29c9c6016a0 Signed-off-by: Yu Haonong <yuhaonong@gmail.com>
1 parent 33034b1 commit ca13b15

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/java/android/widget/Switch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ private boolean getTargetCheckedState() {
675675
@Override
676676
public void setChecked(boolean checked) {
677677
super.setChecked(checked);
678-
mThumbPosition = checked ? getThumbScrollRange() : 0;
678+
mThumbPosition = isChecked() ? getThumbScrollRange() : 0;
679679
invalidate();
680680
}
681681

0 commit comments

Comments
 (0)