Questions tagged [android-databinding]

Data Binding Library to write declarative layouts and minimize the glue code necessary to bind your application logic and layouts. The Data Binding Library offers both flexibility and broad compatibility — it's a support library, so you can use it with all Android platform versions back to Android 2.1 (API level 7+).

The Data Binding Library offers both flexibility and broad compatibility — it's a support library, so you can use it with all Android platform versions back to Android 2.1 (API level 7+).

To use data binding, Android Plugin for Gradle 1.5.0-alpha1 or higher is required.

Official API Documentation

Data Binding Guide

2508 questions
54
votes
4 answers

Android + Data Binding @style

While using the new data binding api, I found that you can't bind to the "style" attribute. Compiler complains that it can't find the style. However, if I simply set the style as is, it'll find it just fine. For example: doesn't…
worked
  • 5,762
  • 5
  • 54
  • 79
53
votes
7 answers

Android data binding : view does not update when property is changed

let me first start with showing the code: build.gradle (module): android { compileSdkVersion 24 buildToolsVersion "24.0.2" dataBinding { enabled = true } defaultConfig { applicationId "com.example.oryaa.basecalculator" minSdkVersion 15 …
user5190190
52
votes
7 answers

data binding - safeUnbox warning

after i upgrade AS gradle version to 2.3.0, data binding encounter a warning : Warning:selectMap[index] is a boxed field but needs to be un-boxed to execute selectMap[index] ? @android:color/white : @android:color/transparent. This may cause NPE…
51
votes
6 answers

Best practice for Android MVVM startActivity

I am building an Android App using MVVM and DataBinding. And I have a function inside my ViewModel that starts an Activity. Is it okay to have an onClick call inside a ViewModel? Like this. public class MyViewModel { public void onClick(View…
Felipe Kenji Shiba
  • 704
  • 1
  • 6
  • 10
51
votes
12 answers

Set text color using data binding on Android

I'm trying to set TextView text color using data binding library android:textColor="@{holder.getTitleColor(context, item)}" where the method in Holder class is defined like below public int getTitleColor(Context context, Item item) { ... } No…
tomrozb
  • 25,773
  • 31
  • 101
  • 122
50
votes
7 answers

Android spinner Data Binding using XML and show the selected values

I am using the new android data binding and it works great. I am able to perform data binding using EditText, TextView, Radio and checkbox. Now, I am not able to do the databinding in spinner. Found some clue in below link: Android spinner data…
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
50
votes
6 answers

Create two-way binding with Android Data Binding

I have implemented the new Android data-binding, and after implementing realised that it does not support two-way binding. I have tried to solve this manually but I am struggling to find a good solution to use when binding to an EditText. In my…
Gober
  • 3,632
  • 3
  • 26
  • 33
47
votes
9 answers

Android two way binding with Integer type causes databinding does not exist

I'm having some issue with implementing two way binding with an Integer data type. public class User { private String firstName; private String lastName; private int age; public User() {} public void setFirstName(String…
ads
  • 1,703
  • 2
  • 18
  • 35
45
votes
6 answers

Android binding adapter passing multiple arguments cause error

I am quite new in Android Data Binding. I am following this tutorial: Data Binding Library. I am trying to do an adapter that receive multiple parameters. This is my code: XML
IrApp
  • 1,823
  • 5
  • 24
  • 42
45
votes
5 answers

Syntax for conditional statements in Android XML Layout

With databinding we now often see codes in layout files like this: and then later: android:visibility="@{displayIt ? View.VISIBLE : View.GONE}" (of course android.view.View must first be imported for…
htwu
  • 467
  • 1
  • 4
  • 9
43
votes
2 answers

Where to place android BindingAdapter method?

This has to be the most basic of question but after a full day of reading tutorials and the documentation here I can't seem to understand where to put these methods. None of the guides mention where this thing is placed it just mentions to use the…
chaser
  • 3,107
  • 4
  • 29
  • 34
42
votes
4 answers

Include tag and dataBinding

I want to use one of my layouts multiple times in the same view using include. Let's say I have a custom.xml including some TextViews. custom.xml:
Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
38
votes
4 answers

android:entries in recyclerview

I have used listview with entries attribute like below : Now i am converting it to…
Ravi
  • 34,851
  • 21
  • 122
  • 183
37
votes
3 answers

Android data binding "Missing import expression although it is registered" after upgrade to gradle 5.0

After I upgrade my Android studio to 3.4, Android Gradle Plugin to 3.4 and gradle to 5.1.1 I got the data binding errors like below I have made sure I cleaned project and rebuild, I have cleared cache and restarted AS. This issue never happened…
CodingTT
  • 1,125
  • 3
  • 14
  • 23
37
votes
3 answers

Using attribute resources (?attr/) in layout binding?

Data binding in Android currently seems to support the following reference resources (according to data binding guide): @array, @color, @int, @dimen, @string... which will give referenced values as arguments in static @BindingAdapter method. For…
hidro
  • 12,333
  • 6
  • 53
  • 53