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
263
votes
16 answers

How to use data-binding with Fragment

I'm trying to follow data-binding example from official google doc https://developer.android.com/tools/data-binding/guide.html except that I'm trying to apply data-biding to a fragment, not an activity. the error I'm currently getting when compiling…
dark_ruby
  • 7,646
  • 7
  • 32
  • 57
209
votes
13 answers

How do I use databinding to combine a string from resources with a dynamic variable in XML?

I have a TextView which has a hardcoded string and I have a dynamic variable that I want to put at the end of this string. This is my code:
Ignacio Perez
  • 2,341
  • 3
  • 13
  • 18
204
votes
9 answers

DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'

Gets following warning when building the project DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'. I am using Android Studio Canary 6
user158
  • 12,852
  • 7
  • 62
  • 94
179
votes
5 answers

android databinding using "&&" logical operator

I am trying to use the and "&&" operator in xml using Android databinding, android:visibility="@{(bean.currentSpaceId == bean.selectedSpaceId **&&** bean.currentSpaceId > 0)? View.VISIBLE: View.GONE}" but I got the compilation…
chubao
  • 5,871
  • 6
  • 39
  • 64
177
votes
8 answers

Android Data Binding using include tag

Update note: The above example works properly, because release 1.0-rc4 fixed the issue of needing the unnecessary variable. Original question: I do exactly as it is described in the documentation and it does not work: main.xml:
174
votes
22 answers

Kotlin-android: unresolved reference databinding

I have following fragment class written in Java using the new databinding library import com.example.app.databinding.FragmentDataBdinding; public class DataFragment extends Fragment { @Nullable private FragmentDataBinding mBinding; …
Mikhail
  • 3,666
  • 4
  • 30
  • 43
145
votes
35 answers

Data Binding class not generated

I am using Data Binding in my project, when using and in my xml binding class is not generated. For example i have activity_main.xml
Ravi
  • 34,851
  • 21
  • 122
  • 183
141
votes
4 answers

Use data binding to set View visibility

Trying to set visibility of View using custom variable, but error occurs: Identifiers must have user defined types from the XML file. visible is missing it. Is it possible to set view visibility using data binding? Thanks.
Konstantin Konopko
  • 5,229
  • 4
  • 36
  • 62
138
votes
13 answers

I want to concat two strings for a TextView in android, Data Binding Api

Im using DataBinding Api for setting the views in android layouts. Here is my layout. layout.xml
128
votes
4 answers

Android : Difference between DataBinding and ViewBinding

We are using DataBinding since Jetpack release. Android documentation indicates that ViewBinding was added in Android Studio 3.6 Canary 11+. I read the documentation but its looks similar to DataBinding. Can anyone explain what's the difference…
117
votes
18 answers

Set drawable resource ID in android:src for ImageView using data binding in Android

I'm trying to set drawable resource ID to android:src of ImageView using data binding Here is my object: public class Recipe implements Parcelable { public final int imageResource; // resource ID (e.g. R.drawable.some_image) public final…
Yuriy Seredyuk
  • 1,643
  • 2
  • 15
  • 18
110
votes
13 answers

How should I get Resources(R.string) in viewModel in Android (MVVM and databinding)

I am currently using databinding and MVVM architecture for android. What would be the best way to get string resources in ViewModel. I am not using the new AndroidViewModel component, eventbus or RxJava I was going through the aproach of interfaces…
Shubham
  • 2,627
  • 3
  • 20
  • 36
108
votes
4 answers

How to use Data Binding and Kotlin in Android Studio 3.0.0

I just started to use Android Studio 3.0.0, but every time I try to build my project I get this error: Error:Circular dependency between the following tasks: :app:compileDebugKotlin +--- :app:dataBindingExportBuildInfoDebug | \---…
103
votes
34 answers

Cannot find symbol DataBindingComponent on Android Studio 3.2 Canary 16 Kotlin project

I just created a new project on Android Studio 3.2 Canary 16 with Kotlin enabled. Then I also enabled data binding, but I'm getting an error saying that it could not find the DataBindingComponent class. Here's my project gradle: // Top-level build…
juliano.net
  • 7,982
  • 13
  • 70
  • 164
97
votes
9 answers

How to set Image resource to ImageView using DataBinding

How can we use data binding in android to put image resource in an ImageView?
George Thomas
  • 4,566
  • 5
  • 30
  • 65
1
2 3
99 100