2017-05-18 33 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