【问题标题】:How to set information in xml from a model of Data Binding in attributes of a custom view如何在自定义视图的属性中从数据绑定模型在 xml 中设置信息
【发布时间】:2020-08-08 12:04:02
【问题描述】:

有两个自定义属性。

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

attrs 或逻辑数据绑定没有错误,因为我可以在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】:

    使用

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

    插入

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

    【讨论】:

    • 我不知道如何帮助我进行双向绑定,但我尝试了它并没有帮助我。顺便说一句,也许这取决于模型列表。 (我改变了问题,因为它不适合列表)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 2016-05-18
    相关资源
    最近更新 更多