Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android-Binding "type" associated with an element type "variable" must not contain the '<' character

I get the following error: The value of attribute "type" associated with an element type "variable" must not contain the '<' character.

And type="ObservableField"/> is colored red in xml.

Any ideas?

 <?xml version="1.0" encoding="utf-8"?>
 <layout>

<data>

<import type="android.databinding.ObservableField"/>
<variable name="field" type="ObservableField<String>"/>

</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="match_parent">

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="72dp"
    android:text="@{field.get()}"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="181dp"
    android:layout_marginEnd="149dp"
    android:layout_marginStart="147dp"
    android:layout_marginTop="191dp"
    android:text="Button"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

</android.support.constraint.ConstraintLayout>

</layout>
like image 785
Nick Avatar asked Jul 14 '18 14:07

Nick


People also ask

What is data binding in Android example?

In Android, the Data Binding Library is a support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.

What is Binding in Android Studio?

View binding is a feature that allows you to more easily write code that interacts with views. Once view binding is enabled in a module, it generates a binding class for each XML layout file present in that module.

What is two way data binding Android?

The @={} notation, which importantly includes the "=" sign, receives data changes to the property and listen to user updates at the same time. // Avoids infinite loops.


2 Answers

A little late, but you can do it this by replacing the < and > for &lt; and &gt;, respectively.

Like this: <variable name="field" type="ObservableField&lt;String&gt;"/>

like image 111
Renan Arceno Avatar answered Sep 26 '22 16:09

Renan Arceno


try this instead

<?xml version="1.0" encoding="utf-8"?>
 <layout>

<data>

<variable name="field" type="android.databinding.ObservableField"/>

</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="match_parent">

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="72dp"
    android:text="@{field.get}"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="181dp"
    android:layout_marginEnd="149dp"
    android:layout_marginStart="147dp"
    android:layout_marginTop="191dp"
    android:text="Button"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

</android.support.constraint.ConstraintLayout>

</layout>

and visit this for more details

like image 38
Abdulmalek Dery Avatar answered Sep 26 '22 16:09

Abdulmalek Dery