【问题标题】:Android DataBinding Cannot 'cannot find symbol variable' error when i use include Tag当我使用包含标签时,Android DataBinding 无法“找不到符号变量”错误
【发布时间】:2016-02-02 03:01:39
【问题描述】:

test.xml:

<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <include
        android:id="@+id/include_content"
        layout="@layout/content" />

    </FrameLayout>
 </layout>

内容.xml:

<layout  xmlns:android="http://schemas.android.com/apk/res/android">
  <FrameLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="test button"/>
  </FrameLayout>
</layout>

Java 代码:

@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {

    super.onCreate(savedInstanceState, persistentState);
   TestBinding binding=DataBindingUtil.setContentView(this, R.layout.test);       
          Button button = binding.includeContent.button;

}

当我运行应用程序时,Android Studio 构建错误“找不到符号变量 includeContent”

我错过了什么?

【问题讨论】:

    标签: android


    【解决方案1】:

    检查这个答案。
    基本上,如果您使用 1.0-rc3 或更低版本,则需要将值传递给包含的布局。
    如果您使用 1.0-rc4 或更高版本,它应该可以在不传递值的情况下工作。

    Android Data Binding using include tag

    【讨论】:

    • @ZeeBmChan 欢迎您,请将此标记为答案,以便对其他人有所帮助!
    • 这是什么1.0-rc3 1.0-rc4?没有依赖性。我们只需要在gradle中将android.buildFeatures.dataBinding标记为true
    • 请检查日期。这是一个非常古老的问题和答案。那个时候我们没有你说的那个选项,而且lib还不够成熟
    猜你喜欢
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多