Android equivalent of KVO?


#1

Hello,

I was reading chapter 12 and saw that a code example updated a model class instance and button text that displayed some of the information held in the model. I was wondering if Android has an equivalent of KVO, thinking that the way I would do something similar in iOS would be to bind data changing in the model to text in the button?

Thanks,


#2

There is no direct equivalent in Android to KVO. A few things you can investigate are:

Java Beans’ “Property Change” API, a la:
developer.android.com/reference/ … pport.html

Java’s Observer/Observable API:
developer.android.com/reference/ … vable.html

In either case, you’re going to be doing the work of manually notifying listeners and ensuring things like thread safety. The Property Change API is most similar to KVO, but you don’t get the magic quite like you do with Cocoa.