Android : Difference between DataBinding and ViewBinding

According to the official docs: ViewBinding Only binding views to code. DataBinding Binding data (from code) to views + ViewBinding (Binding views to code) There are three important differences With view binding, the layouts do not need a layout tag You can’t use viewbinding to bind layouts with data in xml (No binding expressions, no … Read more

Kotlin-android: unresolved reference databinding

Try use this configuration: In main build.gradle: buildscript { ext.kotlin_version = ‘<kotlin-version>’ ext.android_plugin_version = ‘2.2.0-alpha4’ dependencies { classpath “com.android.tools.build:gradle:$android_plugin_version” //… rest of the content } } App build.gradle: android { dataBinding { enabled = true } } dependencies { kapt “com.android.databinding:compiler:$android_plugin_version” } kapt { generateStubs = true }

android databinding using “&&” logical operator

&& should be rendered as &amp;&amp;. The official data binding guide has examples of comparison operators where these XML entities are used, for example android:visibility=”@{age &lt; 13 ? View.GONE : View.VISIBLE}” Edit The example expressions I mentioned in the answer disappeared from the English version of the docs since this answer was written. They do … Read more

Android Data Binding using include tag

The problem is that the included layout isn’t being thought of as a data-bound layout. To make it act as one, you need to pass a variable: buttons.xml: <layout xmlns:andr…> <data> <variable name=”foo” type=”int”/> </data> <Button android:id=”@+id/button” ….” /> main.xml: <layout xmlns:andr… … <include layout=”@layout/buttons” android:id=”@+id/buttons” app:foo=”@{1}”/> …. Then you can access buttons indirectly through … Read more

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

You can do this even simplier: android:text= “@{@string/generic_text(profile.name)}” you string should be like this: <string name=”generic_text”>My Name is %s</string> Edit: Of course you can use as many variables as you need: android:text= “@{@string/generic_text(profile.firstName, profile.secondName)}” <string name=”generic_text”>My Name is %1$s %2$s</string> It works just because it’s designed in data binding. More in docs: https://developer.android.com/topic/libraries/data-binding/expressions#resources

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

Starting from Android Gradle Plugin 4.0.0-alpha05 there is a new block called buildFeatures to enable build features. So in order to enable databinding with new AGP plugin you have do like following in module (ex: app) level gradle file build.gradle ( Groovy DSL ) // shorter version // android.buildFeatures.dataBinding true // longer version android { … Read more

How to use data-binding with Fragment

The data binding implementation must be in the onCreateView method of the fragment, delete any data Binding that exist in your OnCreate method, your onCreateView should look like this: public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { MartianDataBinding binding = DataBindingUtil.inflate( inflater, R.layout.martian_data, container, false); View view = binding.getRoot(); //here data must … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)