Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data binding: Attribute is missing the Androld namespace prefix

Tags:

android

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
like image 657
Alex Avatar asked Nov 27 '17 13:11

Alex


People also ask

What is data binding in Android MVVM?

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.

Why is xmlns missing the Android namespace prefix?

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.

What is data binding library in Android?

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.

Why can't I see namespace attribute in my XML file?

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"

What does * mean in a binding adapter?

* 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.


1 Answers

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>
like image 195
Pavneet_Singh Avatar answered Oct 18 '22 03:10

Pavneet_Singh