Closed GoogleCodeExporter closed 9 years ago
One of the solutions:
I'd imagine to do it via some kind of observer pattern. Each view (created
using getNewView() or updateView() should register tio become observers of the
selected states (you will need to create your own
"SelectedStateObserverManager" and let the views register in it.
Then (as you can see in the example SimpleStandardAdapter which you will have
to either copy or extend) - you should remember the id of the node (for example
as tag in checkbox object) which is the location in the tree (from the manager
you can easily find the parent of given id). You can use it and keep somewhere
on a side how many children are already selected per parent (or check it
dynamically).
Then every time someone makes a selection of a checkbox (you will set
onCheckChangeListener for it), you could update the count of selected items per
parent and then fire all the registered observers. Every view could then (in
the observer notification handling) could check how many of views under the
parent are already selected. And if there are exactly 2 of them - view would
make the checkbox disabled (of course only if it is not selected already).
The same check (how many children of my parent are already selected) will have
to be done when the view is created or updated (getNewView or updateView in the
adapter) - so that when you scroll out/in and views are re-created they are
already disabled/enabled if needed.
Something like that would do the job.
Original comment by ja...@potiuk.com
on 3 Apr 2011 at 9:13
Original issue reported on code.google.com by
frank.eg...@gmail.com
on 2 Apr 2011 at 9:31