”ActionListener” for a nitfy checkbox? (Solved)

I have a checkbox in my xml document. If i add an the method is triggered as intended but the checkbox stops functioning like if my onClick overrides the built-in method that toggles the checkbox. So how do i get a method to run when a checkbox i toggled?

How about toggling it yourself from code when the method is called?

This requires Nifty 1.3 and that you have set the id attribute for the checkbox. All you need to do is to add this method to your ScreenController:



[java] @NiftyEventSubscriber(id=“MyCheckBoxId”)

public void onAllCheckBoxChanged(final String id, final CheckBoxStateChangedEvent event) {

// do something with the event

}[/java]



That’s all! Nifty, isn’t it?



PS: This will work only at ScreenControllers. You can subscribe to events on other instances too. This needs to be documented and blogged about tho.

normen said:
How about toggling it yourself from code when the method is called?

That's quite simple, should have thought about that myself. I tried it and it worked fine. I also tried voids solution which also worked :)