
In the earlier posts we have seen how to use DataBinding, Setting custom font and Image loading. Today we will discuss about two-way DataBinding.
What is Two-way DataBinding?
Till now we have seen how to set values to xml view, but in controls like EditText we need to fetch value. In simple term two-way DataBinding is setting values to that control and fetching it after having some changes.
ObservableField
ObservableField can be used instead of extending BaseObservable class. ObservableFields are self-contained observable objects that have a single field.
Continue Reading →

We have already seen DataBinding Basics and setting fonts through DataBinding in previous tutorials. Today we will take a look at Image loading with databinding .
Step 1 : Define POJO/Model class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
public class PersonModelClass { String name,designation,image_url; public PersonModelClass(String name, String designation, String image_url) { this.name = name; this.designation = designation; this.image_url = image_url; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDesignation() { return designation; } public void setDesignation(String designation) { this.designation = designation; } public String getImage_url() { return image_url; } public void setImage_url(String image_url) { this.image_url = image_url; } } |
Continue Reading →

Today we will learn about setting custom font through XML with DataBinding. We already know how to set custom font through java code.
|
Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/font name.ttf"); tv.setTypeface(custom_font); |
It will set font type for given TextView or other View. But what if we have more number of TextViews/EditTexts throughout the application and that also with multiple custom fonts? We need to declare those number of objects for TextView/EditText as well as for TypeFace declaration. Don’t you think it will increase number of codes? Yes, so other option will come in your mind is to create Custom TextView/EditText. Not a bad idea but we have 15-20 custom fonts throughout the app so creating those number of Custom class would realy be a bad idea. So what is the simplest and easy solution? Answer is DataBinding.
Continue Reading →

In I/O 2015 Google announced a data binding library for Android. With data binding, you create an ongoing link between an element in the user interface and a value. Data binding is the process that establishes a connection between the application UI and business logic.
As a developer we always try to do tasks with lesser code, findViewById and setText would be the things which will increase line of codes. Data binding eliminates needs of these methods.
DataBinding is a support library so you can use it with the version higher than Android 2.1. Now we will see step by step instruction for how to use DataBinding in real time.
Continue Reading →