I have multiple Check Boxes in an Android activity and I want to implement a tree-like functionality with these Check Boxes.
For example when the user clicks on a checkBox, all sub checkBoxes should also be toggled. Similarly, when all sub checkBoxes are in the same state, the parent checkBox should be notified about this and be toggled accordingly.
In this second case, the parent checkBox will be toggled but should not toggle all the child checkBoxes (because it was not actively clicked by the user but rather toggled as a consequence of all children being toggled)
I toggle the checkBoxes using checkBox.setChecked(isChecked)
.
This leads to the checkBox's OnCheckedChangeListener
being called which in turn calls a method responsible for updating all the children.
So I need to find a way to differentiate between user interaction and setting the checkBox state from code. I tried using checkBox.setOnClickListener()
, however the onClickListener is always notified after the checkBox' state has already changed.
Aucun commentaire:
Enregistrer un commentaire