参考资料在数据绑定中包含布局的视图

时间:2018-07-16 07:51:24

标签: android xml

我打算是 将EditText(id:edit_cmt_content)的文本传递到toolbar.xml

然后检查文本的长度。但这不起作用。

错误消息:

  

发现数据绑定错误。   **** /数据绑定错误**** msg:找不到访问者packageName.databinding.LayoutCommentBinding.editCmtContent

我有三个布局。

toolbar.xmlcmt.xmlfragment.xml,其中包括toolbar.xmlcmt.xml

这是fragment.xml

<data>
    <variable
        name = "binding"
        type = "packageName.databinding.CmtBinding"/>
</data>

<android.support.constraint.ConstraintLayout
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    >

    <include
        android:id="@+id/toolbar"
        app:comment = "@{binding.editCmtContent.getText()}"
        layout = "@layout/toolbar_comment_write" />

    <include
        android:id="@+id/layout_cmt"
        layout = "@layout/cmt" />
</android.support.constraint.ConstraintLayout>

这是toolbar.xml代码

<data>
    <variable
        name = "comment"
        type = "java.lang.String"/>
</data>

<android.support.v7.widget.Toolbar
    android:id = "@+id/toolbar"
    style = "@style/ToolbarDefault"
    android:layout_width = "match_parent"
    >

    <android.support.constraint.ConstraintLayout
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        >
       ...
        <TextView
            android:id = "@+id/text_cmt_complete"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:textColor = "@{comment.length !=0 ? @color/colorPrimary : @color/colorWarmGray }"
            />

    </android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>

这是cmt.xml

<android.support.constraint.ConstraintLayout
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    >
    ...

    <EditText
        android:id = "@+id/edit_cmt_content"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        />
</android.support.constraint.ConstraintLayout>

0 个答案:

没有答案