Android Studio 3.0
classpath 'com.android.tools.build:gradle:3.0.1'
set
dataBinding {
enabled = true
}
I want to use data binding.
Here my xml layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<data>
<variable
name="offer" type="com.myproject.customer.Offer" />
</data>
</android.support.constraint.ConstraintLayout>
But I get error:
Attribute is missing the Android namespace prefix
Up until now, we've used Data Binding to update the View from the ViewModel. LiveData is a handy data holder that acts as a container over the data to be passed. The best thing about LiveData is that it is lifecycle aware. So if you are in the background, the UI won't try to update.
Attribute is missing the Android namespace prefix This error is related to one of the XML files in your Android Workspace Project, Reason ? You have missed out xmlns namespace attribute in one of your XML: AndroidManifest.xml, layout.xml, or any Custom XML that you have added.
The Data Binding Library is an Android Jetpack library that allows you to bind UI components in your XML layouts to data sources in your app using a declarative format rather than programmatically, reducing boilerplate code. This codelab has been designed for those with some Android development experience.
You have missed out xmlns namespace attribute in one of your XML: AndroidManifest.xml, layout.xml, or any Custom XML that you have added. Check that these XML files contains, xmlns:android="http://schemas.android.com/apk/res/android"
* Showcases Binding Adapters with multiple attributes. Note that this adapter is called * whenever any of the attribute changes. This Binding Adapter is not used if any of the attributes are missing.
Your data-binding XML root should be layout
tag
From Docs
Data-binding layout files are slightly different
and start with a root tag of layout followed by a data element
and a view root element. This view element is what your root would be in a non-binding layout file.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.User"/>
</data>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.constraint.ConstraintLayout>
</layout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With