binding-collection-adapter
binding-collection-adapter copied to clipboard
BaseAdapter#isEnabled support
Hey,
I was wandering is it possible to easly use BaseAdapter#isEnabled function. I was looking at the source code of the BindingListViewAdapter however no straight forward solution comes into my mind. Any hints?
Can you give an example of where you are trying to call it? You can just get a reference to the adapter and call it. Or you can subclass the adapter and have access to it that way.
Looked up how that method is used, seems like a reasonable thing to add. In the mean time, subclassing the adapter should work fine.
Added in 1.0.0
see README for details.
Great news. Do you have any plans to add change observer in order to invalidate adapter data if itemEnabled field has changed?
Not sure I understand, could you give an example where the current implementation does not work?
Correct me if I am wrong, because I did not try latest version, i just read the code. If I want to disable one of the items in runtime (eg. result of some validation) I have will change itemEnabled based on some viewmodel property:
adapter.setItemEnabled(new BindingListViewAdapter.ItemEnabled<ProductViewModel>() {
@Override
public boolean isEnabled(int position, ProductViewModel product) {
return product.isInStock
}
});
Then if isInStock will change after populating a list, will adapter be notified in order to update view state (notifyDataSetChanged)?
Alright, I'll see what you mean. I'm a bit hesitant on forcing a dataSetChange if it might not actually be needed. I'm reopening and I'll investigate this further.
Note your example would not trigger a notifyDataSetChanged
since it's only changing the contents of an item.
Thank you for your support. I guess current implementation will be suitable for most cases.
I think it is a good idea to update a documentation with the information when exactly BindingListViewAdapter.ItemEnabled interface will be queried.