gpt4 book ai didi

android - 数据绑定(bind)不支持包含为合并元素的直接子元素

转载 作者:行者123 更新时间:2023-11-29 16:53:50 25 4
gpt4 key购买 nike

我正在尝试对现有项目使用数据绑定(bind)。作为其中的一部分,最初我试图摆脱所有 findViewById() 方法。

现在的问题是,我的布局如下:-

<merge >
<include
android:id="@+id/my_login_process_view"
layout="@layout/content_my_message_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</merge>

在将 android 绑定(bind)添加到此布局(将布局添加为父标记)后,它会抛出如下错误。

数据绑定(bind)不支持作为合并元素的直接子元素包含在内

我已经关注了android官方指南Android data binding .

我只是想摆脱上面布局文件的 findViewById。

如有任何建议,我们将不胜感激。谢谢

最佳答案

您提供的链接显然表示不受支持。

Data binding does not support include as a direct child of a merge element. For example, the following layout is not supported:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="user" type="com.example.User"/>
</data>
<merge>
<include layout="@layout/name"
bind:user="@{user}"/>
<include layout="@layout/contact"
bind:user="@{user}"/>
</merge>
</layout>

根据官方文档,它的工作原理是下面的代码

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/name"
bind:user="@{user}"/>
<include layout="@layout/contact"
bind:user="@{user}"/>
</LinearLayout>
</layout>

关于android - 数据绑定(bind)不支持包含为合并元素的直接子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45556479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com