Gradle (Module:app) Configuration
android {
....
dataBinding {
enabled = true
}
}
Data model
public class Item {
public String name;
public String description;
public Item(String name, String description) {
this.name = name;
this.descr...
If your model has private methods, the databinding library still allows you to access them in your view without using the full name of the method.
Data model
public class Item {
private String name;
public String getName() {
return name;
}
}
Layout XML
<?xml versi...
Data model
public class Item {
private String name;
public String getName() {
return name;
}
}
Layout XML
You must import referenced classes, just as you would in Java.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="h...
Data Model
public class Item {
private String name;
public String getName() {
return name;
}
public void setName(String name){
this.name = name;
}
}
Layout XML
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:an...
Two-way Data-Binding supports the following attributes:
ElementPropertiesAbsListViewandroid:selectedItemPositionCalendarViewandroid:dateCompoundButtonandroid:checkedDatePickerandroid:yearandroid:monthandroid:dayEditTextandroid:textNumberPickerandroid:valueRadioGroupandroid:checkedButtonRatingBarand...
It's also possible to use data binding within your RecyclerView Adapter.
Data model
public class Item {
private String name;
public String getName() {
return name;
}
}
XML Layout
<TextView
android:layout_width="wrap_content"
android:layou...
Define Interface
public interface ClickHandler {
public void onButtonClick(User user);
}
Create Model class
public class User {
private String name;
public User(String name) {
this.name = name;
}
public String getName() {
return name;
}
...
The Preview pane displays default values for data binding expressions
if provided.
For example :
android:layout_height="@{@dimen/main_layout_height, default=wrap_content}"
It will take wrap_content while designing and will act as a wrap_content in preview pane.
Another example i...
Sometimes we need to perform basic operations like hide/show view based on single value, for that single variable we cannot create model or it is not good practice to create model for that. DataBinding supports basic datatypes to perform those oprations.
<layout xmlns:android="http://schema...