Akhilesh Dhar Dubey
Akhilesh Dhar Dubey

Reputation: 2148

Cannot find the getter for attribute 'android:tag' - Android

I am using data binding, Here I am getting this issue:

Error:(252, 21) Cannot find the getter for attribute 'android:tag'
with value type java.lang.String on com.hdfcfund.investor.views.EditText. 

Although, text attribute working fine but getting error while using tag element.

<?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">
<data>

    <variable
        name="presenter"
        type="com.hdfcfund.investor.folio.step4addnominee.AddNomineePresenter" />

    <variable
        name="nominee"
        type="com.hdfcfund.investor.folio.step1.model.NewInvestorFolioRequest.Nominee" />
</data>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:clickable="true">

                <com.hdfcfund.investor.views.EditText
                    android:id="@+id/et_country"
                    style="@style/EditTextStyleRegularGrey15"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:drawableRight="@drawable/ic_arrow_input"
                    android:focusableInTouchMode="false"
                    android:hint="@string/label_country_1"
                    android:inputType="text"
                    android:onClick="@{()-> presenter.onSpinnerClick(spinnerCountry)}"
                    android:tag="@={nominee.nomineeAddress.countryCode}"
                    android:text="@={nominee.nomineeAddress.countryName}" />


</RelativeLayout>
</layout>

Upvotes: 0

Views: 2264

Answers (2)

George Mount
George Mount

Reputation: 20926

The android:tag attribute doesn't support two-way binding by default. This is because there is no event mechanism to notify when the attribute changes.

You probably intended to use one-way binding:

android:tag="@{nominee.nomineeAddress.countryCode}"

There is no way for the user to change the tag value, so two-way really isn't of a lot of use with that attribute, anyway.

Upvotes: 3

Sergei Bubenshchikov
Sergei Bubenshchikov

Reputation: 5371

You need to define @InverseBindingAdapter to return value from property:

@InverseBindingAdapter(attribute = "android:tag")
public static String getStringTag(EditText view) {
    return String.valueOf(view.getTag());
}

Upvotes: 3

Related Questions