如何在自定义视图的属性中从数据绑定模型设置xml中的信息

问题描述 投票:1回答:1

有两个自定义属性。

<declare-styleable name="CustomImageView">
        <attr name="customTitle" format="reference" />
        <attr name="customDrawableImage" format="reference" />
    </declare-styleable>
<import type="java.util.List"/>
        <variable
            name="models"
            type="List&lt;com.full.path.package.model.Model&gt;" />

<com.full.path.packages.test.CustomImageView
            android:id="@+id/choice_quality_awful_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"          
            app:customTitle="@{models.get(0).title}"/>

属性或逻辑数据绑定中没有错误,因为我可以在app:customTitle中设置另一个字符串,这样就可以了。如果我在其他textView中设置models.get(0).title,它将可以正常工作。但是运行后,出现以下错误(Android Studio认为customTitle是Bidning适配器的命名并尝试找到它)

Cannot find a setter for <com.lucid.dreaming.ui.choicequality.views.QualityImageView app:qualityTitle> that accepts parameter type 'int'

If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.

如何标记它不是绑定适配器?

android kotlin data-binding android-custom-view
1个回答
0
投票

使用

app:customTitle="@={model.title}"

insted of

app:customTitle="@{model.title}"
© www.soinside.com 2019 - 2024. All rights reserved.