Android data-binding (similar to WPF)? Android data-binding (similar to WPF)? wpf wpf

Android data-binding (similar to WPF)?


Native Data Binding

Google has launched its native Data Binding Library!

https://developer.android.com/tools/data-binding/guide.html

Which lets you write your views as such

<TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="@{user.firstName}"/>

But its event wiring mechanism at this time (rc1 version) can't bind to methods on a class extending from Observable (an exception is thrown when compiling; this is a known bug which will be solved).

And sure the lack of two-way binding (which is not expected to be on the first release) is a big drawback.

Anyway, here's a good sample project to play around with https://github.com/saleeh93/data-binding-samples


There is nothing "baked" into the Android SDK which provides equivalent databinding functionality found in MS WPF. Google is providing a lower level interface for the various devices running Android. To date, higher level application frameworks have not emerged from the Android development community. (IMHO, it would take a monster company like Google to create such a thing, given all the different constraints on a framework for all the various Android devices.)

You could create a set of databinding classes in your own application to handle your needs for the MVVM pattern. The "Databinders" would set the relevant event handlers on Android View objects and run some appropriate method on your ViewModel objects in response. They would also translate change events (that you define) on the ViewModel into the appropriate property assignments on the View objects.

Whether that turns out to be worthwhile for your application is a judgment call. My guess is that it would require more effort to write the Databinder classes than just to hook the lower level View event handlers directly. Frameworks are useful primarily when you didn't have to write them yourself.


Well, my Android-Binding project is trying to do data-binding via XML layout. Because there's no build-in method provided by Google (and I can't foresee that Google will do so), that's the reason I started this project.