From 0c8558ad125b2eef2583ae461463cbe74b344dda Mon Sep 17 00:00:00 2001 From: nex3z Date: Sat, 14 Apr 2018 21:38:53 +0800 Subject: [PATCH] Postpone checked state notification. --- .../button/CompoundToggleButton.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/togglebuttongroup/src/main/java/com/nex3z/togglebuttongroup/button/CompoundToggleButton.java b/togglebuttongroup/src/main/java/com/nex3z/togglebuttongroup/button/CompoundToggleButton.java index e9c41f0..42fb5c3 100644 --- a/togglebuttongroup/src/main/java/com/nex3z/togglebuttongroup/button/CompoundToggleButton.java +++ b/togglebuttongroup/src/main/java/com/nex3z/togglebuttongroup/button/CompoundToggleButton.java @@ -45,11 +45,16 @@ public void setChecked(boolean checked) { if (mBroadcasting) { return; } - mBroadcasting = true; - if (mOnCheckedWidgetListener != null) { - mOnCheckedWidgetListener.onCheckedChanged(this, mChecked); - } - mBroadcasting = false; + this.post(new Runnable() { + @Override + public void run() { + mBroadcasting = true; + if (mOnCheckedWidgetListener != null) { + mOnCheckedWidgetListener.onCheckedChanged(CompoundToggleButton.this, mChecked); + } + mBroadcasting = false; + } + }); } }