Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data binding expression not compiling

I'm trying out the new data binding library. I have a weird issue where binding the visibility property is not compiling.

This is a simplified version of the xml file:

<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android">      <data>      <variable         name="header"         type="com.example.EmailHeader" />     </data>      <RelativeLayout ... >          <TextView             ...             android:text="@{header.senderName ?? header.senderAddress}"             android:visibility="@{header.hasAttachment ? View.VISIBLE : View.INVISIBLE}" />      </RelativeLayout> </layout> 

I get the follow message when compiling:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 

java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:Identifiers must have user defined types from the XML file. View is missing it

Everything compiles (and works!) when I remove the android:visiblity declaration.

I don't see what I'm missing here

like image 434
Jordy Langen Avatar asked Aug 18 '15 09:08

Jordy Langen


People also ask

What is ActivityMainBinding?

The above layout filename is activity_main. xml so the corresponding generated class is ActivityMainBinding . This class holds all the bindings from the layout properties (for example, the user variable) to the layout's views and knows how to assign values for the binding expressions.

Which is the correct way to reference bound data in the XML layout?

Layout Binding expressions Expressions in the XML layout files are assigned to a value of the attribute properties using the “ @{} " syntax. We just need to use the basic syntax @{} in an assignment expression. Expressions can be used for many purposes depending on your requirement.


1 Answers

Inside of the data tag you need to also add:

<import type="android.view.View" /> 
like image 182
bwhite Avatar answered Oct 04 '22 11:10

bwhite