Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

164
Views
Android Binding Adapter is not found

Please someone help me! I am going crazy, this should work. I have the following error message when I try to build my Android project:

Android resource linking failed
/Users/slehrbaum/StudioProjects/OneNightComps/Android/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_login.xml:17: error: attribute errorText (aka lehrbaum.de.onenightcomps:errorText) not found.
error: failed linking file resources.

the error message does mention the errorText attribute. I use the errorText attribute in the xml this way (full xml here):

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/usernameField"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/username"
        app:hintEnabled="true"
        app:errorEnabled="true"
        app:errorText="Hi"
        >
        <!--app:errorText="Please provide a username."-->
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:autofillHints="username"
            android:inputType="text"
            android:text="@={viewModel.username}"
            />
    </com.google.android.material.textfield.TextInputLayout>

This is the way I have defined errorText in my Kotlin file (full file here):

object ViewDataBindingExtensions {
    @JvmStatic
    @BindingAdapter("errorText")
    fun bindErrorText(textInputLayout: TextInputLayout, errorText: String) {
        textInputLayout.error = errorText
    }
}

I just don't understand why this happens. Is there some sort of import that I can put in the layout file saying where the BindingAdapter is? Do I have some wrong with my Gradle files? I compared it to the GitHub project in this question which apparently got solved and I do not see the difference to my project. According to the answer I should add the Kotlin-kapt plugin to my Gradle build, which I did. I also looked through the rest of the project and compared. To no avail. You can find my whole build.gradle file here as well as the rest of the project.

Please help me!

8 months ago · Santiago Trujillo
2 answers
Answer question

0

The problem is connected with the way you pass String value to app:errorText.

Use @{``} to pass this value.

Fixed part of fragment_login.xml:

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/username"
    app:hintEnabled="true"
    app:errorText="@{`Please provide a username.`}"
    app:errorEnabled="@{!viewModel.usernameValid}">

Having apply plugin: 'kotlin-kapt' in app/build.gradle is mandatory.

8 months ago · Santiago Trujillo Report

0

Try using

fun bindErrorText(textInputEditText: TextInputEditText, errorText: String) {
 textInputEditText.error = errorText }
8 months ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.