Update 2
The build file is upgraded to have “Wizard-like” choices. No need to choose which target to run, just right-click on the “wizard.xml” and run as ant build.
Update
Just released an ant build file to help generating activity and application. The following tutorial is updated with using ant build.
For those who are already using Android-Binding
I just released the Android-Binding 0.5, this is the first official release to support features in HC/ICS, which includes:
- Action Bar
- Action Modes
As mentioned in previous post, we decided not to include fragment and we provide alternatives to fragments, and those already included in previous releases.
If you are targeting platforms prior to HC, do you need this update? Yes, because we also included binding to ViewPager and to Activity itself.
Please notice about the new binding to activity xml metadata file, as we are deprecating the setAndBindRootView() method.
For everyone
Android-Binding is a MVVM framework for used in Android. It help separate the View (widgets) from View Model (Java codes). This post should be your first post into working with Android-Binding.
Hello World
Before starting the tutorial, please make sure you have:
- A working Eclipse that satisfy the requirement of Android development
- Download the latest version of Android-Binding (v0.5+)
- Download the Ant Build Package (optional, but highly recommended)
In Eclipse click to File > new > Project, follow the following steps:

Min SDK to anything larger than 4 (1.6), Android-Binding supports SDK from 4, and here we just use 8.
Now, we have a basic project to start with. Next we are going to install the android-binding library to the project.
Enabling Android-Binding
Open the workspace folder of Eclipse (in Windows, most probably it is under c:\Users\USERNAME\workspace), under the project folder (HelloAndroidBinding), create a sub-directory called “libs”.
Put the downloaded jar (android-binding-v30.version.jar) into that libs folder.
Extract the antbuild.zip to the root project folder, there should be a “android-binding.ant.jar” file and a “build.xml” file in it.
Back to Eclipse, on Package Explorer, hit F5 to refresh the folder. You should have something like this afterwards:
As seen above, under libs, we have the jar we included, and ADT helps us to setup the link to the library and in Android Dependencies section, we can see the android-binding library there.
We need an application file to initialize Android-Binding, which we can easily created by using the build.xml file. Right Click on the build.xml, and choose Run As -> 2 Ant Build…
And check the Create Application Task and Run:
When prompted with Application Class Name, put in “HelloAndroidBindingApplication” (or anything you want). If you look at the console, it will print a “BUILD SUCCESSFUL” if no problem arise.
The Application file is generated, hit “F5″ in project root folder and you will find this:
Which, the file is generated by Ant.
If you look at the file, you should have something similar to below:
We need to init our Binding Engine, putting BinderV30.init() is all we need. (Note, calling BinderV30 will enables ICS+ features).
Create the Activity Class
We now use Ant build to setup our sample activity class and relevant resource files.
Right Click on Build.xml, choose run as-> 2. Ant Build…
This time, we check the “new-activity” task and uncheck the rest, click run.
When prompted with Activity Name, we put “HelloAndroidBindingActivity” in it. After a short while, “BUILD SUCCESSFUL” appears and refresh the project folder, we have following stuff:
- xml/{name}_metadata.xml: the metadata file for binding the activity
- xml-v14/{name}_metadata.xml: metadata file with Action Bar, only readable by SDK14+ machines
- layout/{name}_layout.xml: main layout file (root view)
- menu/{name}_optionsmenu.xml: Options menu template
- src/{name}.java: The generated activity class
Result
Now run the program, welcome to MVVM.












hi,
This seems like a really nice way.. I followed ur steps, downloaded the files as you mentioned (including the AntBuild).. but when I run the build.xml file. i get the folowing error:
BUILD FAILED
E:\Users\MyName\Android\TestMvvmProject\build.xml:46: taskdef class gueei.binding.gen.ReadFromManifestTask cannot be found
using the classloader AntClassLoader[]
Total time: 264 milliseconds
Why?
Did you include the jar file in the same directory of the build.xml?
I had the same proplem
and I find out that by renaming the
android-binding.jar into android-binding.ant.jar
solve it
including .jar file in root directory with build.xml also gives me the following error:
BUILD FAILED
E:\Users\aamir.habib\Android\TestMvvmProject\build.xml:46: java.lang.UnsupportedClassVersionError: gueei/binding/gen/ReadFromManifestTask : Unsupported major.minor version 51.0
Total time: 252 milliseconds
am i missing anything else?
Thanks.
Did all the steps, built the app. No errors there. But when I run it on Galaxy S III, it’s as if there are no bindings at all. Nothing happens when the button is clicked, value of HelloWorld is not displayed in the TextView. What could be wrong?
hm.. please take a look at the LogCat and see if any log coming from BinderV30/Binder.
Had the error too, apparently there has been a filename change from …ant.jar to just .jar, open the xml, change the path to the current name, and it will run without any problems
Grtz my dawgz!
I run the sample as your guide, but I got an Error when build with ant. The Build failured msessage is as following:
…”HelloAndroidBinding/wizard.xml:59: java.lang.UnsupportedClassVersionError: gueei/binding/gen/ReadFromManifestTask : Unsupported major.minor version 51.0″
But I can see the ReadFromManifestTask.class is in the android-binding.ant.jar
What’s your JRE Version setting on Eclipse? Try JRE1.7