2017-05-18 37 views
0

我使用數據綁定,在這裏我得到這個問題:無法找到屬性的getter「機器人:標籤」 - 安卓

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

雖然,文本屬性工作正常,但在使用標籤元素得到錯誤。

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

回答

1

android:tag屬性不支持雙向默認綁定。這是因爲沒有事件機制可以在屬性更改時進行通知。

你可能打算用單向綁定:

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

有沒有辦法讓用戶更改標籤值,所以雙向真的不是大量使用的具有該屬性無論如何。

1

您需要定義@InverseBindingAdapter從屬性返回值:

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

我建議使用'String.valueOf()'而不是轉換。 – tynn

+0

@tynn,謝謝你的評論 – Sergey