nex3z / ToggleButtonGroup

A group of flowable toggle buttons, with multiple / single selection support and button customization.
Apache License 2.0
421 stars 48 forks source link

OnCheckedChangeListener not called on unselecting the selected item #24

Closed drunkendaddy closed 6 years ago

drunkendaddy commented 6 years ago

I've have a SingleSelectToggleGroup which contains two toggle buttons. On touching the selected item again, it gets unselected, but the OnCheckedChangeListener is not called?

It get called called when selected for the first time or when I toggle selection but not when unselecting a selected item

I need it to be called for my requirements or even simply disable unsecting when touched again (allow toggle select other buttons)

I hope understood my issue. Please reply

drunkendaddy commented 6 years ago

Problem was I am using a custom toggle button, and I was able to get it to work according to my requirements by overriding toggle() method of CompoundToggleButton

@Override
public void toggle() {
    if (isChecked()) {
        return;
    }
    super.toggle();
}

You may close this issue

nex3z commented 6 years ago

The OnCheckedChangeListener notifies checked event (from unchecked to checked) of any button in SingleSelectToggleGroup.

By convention a radio group should have exactly one checked button in it. If you are using the built in LabelToggle or CircularToggle, this is ensured by setting radioStyle to true when they are being added to SingleSelectToggleGroup, as shown here. Similar approach can be found in RadioButton, which forbids checked button to be unchecked.

If you want to uncheck buttons in SingleSelectToggleGroup, you can built your custom button and handle the checked/unchecked state on the button yourself.

You can also use MultiSelectToggleGroup, the OnCheckedStateChangeListener will notify any change, but you will need extra logic to uncheck previous button.