Java - CheckBox Listener
I try to "inhibit" temporarily a CheckBox listener. This is an illustration of my problem. Imagine you have :
Sex: |_| Male |_| Female
Name: |_| Jenny |_| Robert |_| Kate |_| Mike
Pictures: ...
In fact, I would like to display the pictures of the selected persons but as you can see, the 2 series of checkboxes are connected i.e. when I click on "Male" I want Robert and Mike' checkbox selected. But, the fact to make Robert and Mike' checkboxes selected calls their listener. Thus, Robert and Mike' pictures are displayed one time too many.
That's why I would like to "inhibit" the listener on the names' checkboxes when I click on "Male"开发者_如何学Python and the checkboxes corresponding of males (Robert and Mike) are selected automatically.
I hope I have been enough clear.
Thanks for your help.
There are 2 approaches.
When Sex checkbox's listener is invoked you delete the listeners from all Name checkboxes and set their state. Then add the listeners back.
Or Create isUserChanges flag. In all the listeners added to Name checkboxes you check the flag. If it's false you do nothing. IN the first listener (sex) set the flag to false and reset after changing state.
精彩评论