Android数据绑定-如何为ImageView设置contentDescription和src
我试图通过以下方式设置Android数据绑定-如何为ImageView设置contentDescription和src,android,android-databinding,Android,Android Databinding,我试图通过以下方式设置contentDescription: <ImageView android:id="@+id/accountType" android:layout_width="48dp" android:layout_height="48dp" android:contentDescription="@{() -> account.getContentDescription()}"
contentDescription
:
<ImageView
android:id="@+id/accountType"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@{() -> account.getContentDescription()}"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@mipmap/ic_launcher" />
我得到了这个错误:
e:[kapt]发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误。
****/数据绑定错误****msg:找不到android:contentDescription的正确回调类。尝试了java.lang.CharSequence,但它有4个抽象方法,应该有1个抽象方法。
文件:C:\Users\Douglas\AndroidStudioProjects\Currency\app\src\main\res\layout\item\u account.xml
地点:23:42-23:78
****\数据绑定错误****
如果我像这样直接在xml中设置,它将按预期工作:
android:contentDescription="@{context.getResources().getStringArray(R.array.account_type)[account.accountType.ordinal]}"
但是我在Account类中创建了这个方法,以避免一直这样做
如何使用Account类中的方法为
ImageView
设置contentDescription
和app:srcCompat
android:contentDescription="@{account.getContentDescription(context)}"
android:contentDescription="@{account.getContentDescription(context)}"