Android data binding attribute not found

Josh

I am trying to replicate this answer: Setting attribute of child element of included layout

I have a simple custom_edit_text.xml:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable name="hint123" type="String" />
    </data>
    <android.support.design.widget.TextInputLayout
        android:id="@+id/emailInputLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <android.support.v7.widget.AppCompatEditText
            android:id="@+id/emailField"
            android:layout_width="275dp"
            android:layout_height="wrap_content"
            android:paddingBottom="16dp"
            android:paddingTop="14dp"
            android:hint="@{hint123}"
            android:textCursorDrawable="@null"
            android:background="@drawable/edit_text_background"
            android:fontFamily="@font/eina_regular"
            android:textColor="@color/edit_text_color"
            android:textColorHint="@color/edit_text_color"
            android:textSize="15sp"
            />
    </android.support.design.widget.TextInputLayout>
</layout>

And I include it in another file:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <include
            layout="@layout/custom_edit_text"
            app:hint123="Email"/>
</layout>

However the project refuses to compile after a clean & rebuild with the error:

AAPT: error: attribute hint123 (aka inc.company.appname:hint123) not found.

Any ideas?

I also have

dataBinding {
    enabled = true
}

enabled in the app level build.gradle

big_m

I think I've hit upon the solution. To activate data binding, you need to use a @{} expression, and what's in the braces must be valid Java code. So a literal string must be enclosed in quotes... which must be encoded as &quot; inside an XML attribute value. Put it all together and you get:

<include
    layout="@layout/custom_edit_text"
    app:hint123="@{&quot;Email&quot;}"/>

Data binding does work for include files, it's just that the syntax for a literal is a bit convoluted. I had the same issue and this form is working in my project.

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Android Data Binding attribute with void argument

The inflate method for my binding is not found (using Android, Data Binding.)

Android Data binding, The value of attribute "android:text" associated with an element type "TextView" must not contain the '<' character

Android Data Binding NoSuchMethodError

Android + Data Binding @style

Android data binding on drawable

Data binding of CSS class attribute in XML view

viewPager e data binding android

Data Binding e Lambda no Android

Android Data binding for child class

Generic form of binding data android

AutoCompleteTextView or Spinner Data binding in Android

Android Data Binding e Kotlin

Android Data Binding - EditText SetError

Realm messes with Android data binding

viewPager e data binding android

AAPT: error: attribute android:requestLegacyExternalStorage not found

No resource identifier found for attribute 'roundIcon' in package 'android'

Android Data Binding - how to use ViewStub with data binding

How can I add a `/` to an attribute I'm binding data to?

Aurelia: data binding issue with the primary property of a custom attribute

Data binding, TabLayout e “No view found for id for fragment”

Error in mutate_impl(.data, dots) : binding not found

Android Data Binding library - unresolved reference

Android Data Binding: visibility on include tag

Android data binding is not working with <merge> attributes

Comparação de strings no Android Data Binding

Pass views in OnFocusChange in data binding Android

Erro de XML do Android Data Binding

TOP lista

  1. 1

    R Shiny: use HTML em funções (como textInput, checkboxGroupInput)

  2. 2

    UITextView não está exibindo texto longo

  3. 3

    Dependência circular de diálogo personalizado

  4. 4

    Acessando relatório de campanhas na AdMob usando a API do Adsense

  5. 5

    Como assinar digitalmente um documento PDF com assinatura e texto visíveis usando Java

  6. 6

    R Folheto. Dados de pontos de grupo em células para resumir muitos pontos de dados

  7. 7

    Setas rotuladas horizontais apontando para uma linha vertical

  8. 8

    O Chromium e o Firefox exibem as cores de maneira diferente e não sei qual deles está fazendo certo

  9. 9

    Definir um clipe em uma trama nascida no mar

  10. 10

    Por que meus intervalos de confiança de 95% da minha regressão multivariada estão sendo plotados como uma linha de loess?

  11. 11

    Como dinamizar um Dataframe do pandas em Python?

  12. 12

    regex para destacar novos caracteres de linha no início e no fim

  13. 13

    Why isn't my C# .Net Core Rest API route finding my method?

  14. 14

    Como obter a entrada de trás de diálogo em treeview pyqt5 python 3

  15. 15

    Tabela CSS: barra de rolagem para a primeira coluna e largura automática para a coluna restante

  16. 16

    How to create dynamic navigation menu select from database using Codeigniter?

  17. 17

    Como recuperar parâmetros de entrada usando C #?

  18. 18

    Changing long, lat values of Polygon coordinates in python

  19. 19

    Livros sobre criptografia do muito básico ao muito avançado

  20. 20

    Método \ "POST \" não permitido no framework Django rest com ações extras & ModelViewset

  21. 21

    Pesquisa classificada, conte números abaixo do valor desejado

quentelabel

Arquivo