DependentObservable depending on ObservableCollections

59 views
Skip to first unread message

mai...@gmail.com

unread,
Jan 9, 2013, 7:47:23 AM1/9/13
to android...@googlegroups.com
Hi.

Are DependentObservable depending on ObservableCollections being re-evaluated on collectionChanged() collection event (e.g. when one add or remove any element)?

Thanks!

Andy Tsui

unread,
Jan 13, 2013, 9:36:04 PM1/13/13
to AndroidBinding
No. DependentObservable observes only IObservables on simple set() operation. Individual item change event is not observed. 

mai...@gmail.com

unread,
Jan 14, 2013, 7:05:46 AM1/14/13
to android...@googlegroups.com
Ok, thanks.

Nevertheless it could be useful to parametrize such behavior, since having a bound view whose visual state is related to specific criteria applied to a collection is quite a common case...am I wrong?

At this time I'm compelled to use a dummy booleanobservable which dependant depends on,  toggled whenever I update collection...

Andy Tsui

unread,
Jan 14, 2013, 7:32:32 PM1/14/13
to AndroidBinding
Collection Change Event consists of different states, it can either be Reset/Add/Delete/Change which is over complicated for the general DependentObservable to handle.. but it is easy to create your own, take your boolean obs as example, you can implement it with CollectionObserver, and toggle whenever the collection changed. 

Andy Tsui

unread,
Mar 27, 2013, 10:39:21 PM3/27/13
to AndroidBinding

Lorenzo Maiorfi

unread,
Dec 1, 2013, 7:10:29 AM12/1/13
to android...@googlegroups.com
COuld you please post a micro-snippet of a simple use case concerning for example a viewmodel method being invoked whenever a member ArrayListObservable changes? I'm a little confused about how to use CollectionObserver interface and how to "inject" it while creating a DependantObservable.

Thank you very much!

Andy Tsui

unread,
Dec 5, 2013, 12:27:47 PM12/5/13
to AndroidBinding
I think the example in the blog post should explain that, any particular problem you have on the example?


--
You received this message because you are subscribed to the Google Groups "AndroidBinding" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbindin...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Lorenzo Maiorfi

unread,
Dec 5, 2013, 3:26:51 PM12/5/13
to android...@googlegroups.com
I was looking for something like that (now that I have understood how to get it done it seems much, much simpler :) ):

public class BasicViewModel
{
    [...]
    public final ArrayListObservable<BasicItemViewModel> Items = new ArrayListObservable<BasicItemViewModel>(BasicItemViewModel.class);

    CollectionObserver _itemsCollectionObserver;
    [...]

   _itemsCollectionObserver=new CollectionObserver()
   {
    @Override
    public void onCollectionChanged(IObservableCollection<?> arg0, CollectionChangedEventArg arg1, Collection<Object> arg2)
    {
    BasicViewModel.this.ItemsStatus.set(String.format("%d items",arg0.size()));
    }
    };
[...]
Reply all
Reply to author
Forward
0 new messages