Пример #1
0
  /**
   * Changes the checked state of this button.
   *
   * @param checked true to check the button, false to uncheck it
   */
  public void setChecked(boolean checked) {

    if (mChecked != checked) {
      mChecked = checked;

      mBtnPos = checked ? mBtnOnPos : mBtnOffPos;
      mRealPos = getRealPos(mBtnPos);
      invalidate();

      // Avoid infinite recursions if setChecked() is called from a
      // listener
      if (mBroadcasting) {
        return;
      }

      mBroadcasting = true;
      if (mOnCheckedChangeListener != null) {
        mOnCheckedChangeListener.onCheckedChanged(CheckSwitchButton.this, mChecked);
      }
      if (mOnCheckedChangeWidgetListener != null) {
        mOnCheckedChangeWidgetListener.onCheckedChanged(CheckSwitchButton.this, mChecked);
      }

      mBroadcasting = false;
    }
  }
 @Override
 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
   for (OnCheckedChangeListener listener : listeners) {
     listener.onCheckedChanged(buttonView, isChecked);
   }
 }