Tutorial by Examples

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...
Create interface for clickHandler public interface ClickHandler { public void onButtonClick(View v); } Layout XML <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> ...
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...
public void doSomething() { DialogTestBinding binding = DataBindingUtil .inflate(LayoutInflater.from(context), R.layout.dialog_test, null, false); Dialog dialog = new Dialog(context); dialog.setContentView(binding.getRoot()); dialog.show(); }
Layout XML <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> </data> <LinearLayout android:orientation="vertical" android:layout_wid...

Page 1 of 1