Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android数据绑定-如何为ImageView设置contentDescription和src_Android_Android Databinding - Fatal编程技术网

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)}"