Android 使用DataBinding跟include问题

ChansEbm 2015-11-02 05:41:19
直接上代码吧

test.xml

<?xml version="1.0" encoding="utf-8"?>
<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>



content.xml

<?xml version="1.0" encoding="utf-8"?>
<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="1"/>
</FrameLayout>

</layout>



java 代码:
TestBinding binding;

@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
binding = (TestBinding) viewDataBinding;
Button button = binding.includeContent.button;
}


运行到Button button = binding.includeContent.button;的时候 报错


Error:(11, 39) 错误: 找不到符号
符号: 类 Test1Binding
位置: 程序包 com.appbaba.digital.databinding
...全文
2377 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
amtfnmamtf 2017-06-27
  • 打赏
  • 举报
回复
直接对include设置id,然后对应在binding中会为该id自动生成对应include的layout的另一个binding
肖子理 2017-01-01
  • 打赏
  • 举报
回复
楼主解决没。。
肖子理 2016-11-24
  • 打赏
  • 举报
回复
给include里的文件的根布局加上id,我这样就好了!
琪琪 2016-03-17
  • 打赏
  • 举报
回复
这个还用问?databinding的插件没有做include的递归查找呗,include目前只能findviewbyid找出来了,你可以去给插件开发者建议一下,google官方的吧。
qq_31761061 2016-01-04
  • 打赏
  • 举报
回复
同求,我这个问题卡了几天了
jklwan 2015-11-03
  • 打赏
  • 举报
回复
你这个没有数据处理,没有必要用databinding。而且databinding是用来绑定数据的,并不能用来查找控件,用法就错了。用普通的findbyid来获取button。
fei381895649fei 2015-11-02
  • 打赏
  • 举报
回复
没人知道吗?我也遇到这个问题

80,352

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧