Data Binding的中 include 标签的使用

inclune使用和原来一样,但要如何使数据也在 include中使用呢?

先看看我的布局文件

include的布局文件,也要使用 <layout>标签

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable
name="userInfo"
type="com.zhangqie.databinding.demo10.UserInfo" />
</data> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:id="@+id/tv_tow_mls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{userInfo.dataName}" /> <Button
android:id="@+id/btn_demo10_include"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="include 下的点击" />
</LinearLayout> </layout>

来看看主布局

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <variable
name="userInfo"
type="com.zhangqie.databinding.demo10.UserInfo" /> </data> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{userInfo.dataName}" /> <Button
android:id="@+id/btn_demo10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试" /> <include
android:id="@+id/demo10_ainclude"
layout="@layout/include_test"
app:userInfo="@{userInfo}" /> </LinearLayout>
</layout>

include 中需要把 userinfo对象传给他;

也要给include 添加一个id值

来看看java代码:

public class InCludeActivity extends AppCompatActivity {

    Demo10Binding demo10Binding;

    @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
demo10Binding = DataBindingUtil.setContentView(this,R.layout.demo10);
initView();
} private void initView(){ UserInfo userInfo = new UserInfo("zhangqie"); demo10Binding.setUserInfo(userInfo); demo10Binding.demo10Ainclude.tvTowMls.setText("访问include 中的id"); demo10Binding.demo10Ainclude.btnDemo10Include.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(InCludeActivity.this,"123",Toast.LENGTH_LONG).show();
}
});
}
}

通过已上介绍应该可以简单了解databinding中 include的使用了

android -------- Data Binding的使用 ( 五) include的更多相关文章

  1. Android Data Binding

    Android官方数据绑定框架DataBinding, 1.什么是DataBinding 2.DataBinding基础用法 3.DataBinding原理 4.表达式 5.null检查 6.incl ...

  2. android data binding jetpack I 环境配置 model-view 简单绑定

    android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...

  3. Android Data Binding代码实践(告别findViewById)(四)

    Data Binding实战(一) Data Binding语法解析(二) Data Binding高级用法(三) 好了,继前三篇学习了Data Binding之后,我们可以发现它的强大之处有这么几点 ...

  4. Android Data Binding实战(一)

    在今年Google I/O大会上,Google推出Design Library库的同时也推出了Android Data Binding,那么什么是Data Binding?其名曰数据绑定,使用它我们可 ...

  5. Android Data Binding Library

    Data Binding Library Data Binding Library是一个支持库,允许您使用声明格式(而不是编程)将布局中的UI组件与应用程序中的数据源绑定. 布局通常在调用UI框架方法 ...

  6. Android Data Binding(数据绑定)用户指南

    Android Data Binding(数据绑定)用户指南 http://www.jianshu.com/p/b1df61a4df77 https://github.com/LyndonChin/M ...

  7. android data binding jetpack VIII BindingConversion

    android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...

  8. android data binding jetpack VII @BindingAdapter

    android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...

  9. android data binding jetpack VI 清理一些概念。BR 运算表达式

    android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...

随机推荐

  1. for和while循环的区别

    区别:for循环,就是遍历某一对象,通俗说就是根据循环次数限制做多少次重复操作.while循环,是当满足什么条件的时候,才做某种操作. for为遍历循环 while为直到循环

  2. NodeJs中npm使用

    什么是 NPM npm 之于 Node ,就像 pip 之于 Python , gem 之于 Ruby , pear 之于 PHP . npm 是 Node 官方提供的包管理工具,他已经成了 Node ...

  3. 深入了解JVW

    Java内存组成介绍:堆(Heap)和非堆(Non-heap)内存 按照官方的说法:“Java 虚拟机具有一个堆,堆是运行时数据区域,所有类实例和数组的内存均从此处分配.堆是在 Java 虚拟机启动时 ...

  4. IQR(Inter-Quartile Range)

    IQR(Inter-Quartile Range)在统计中叫内距.内距又称为四分位差.具体如下:内距IQR即Inter-Quartile Range, 这是统计技术上的名词.内距又称为四分位差,是两个 ...

  5. Derek解读Bytom源码-孤块管理

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  6. PS与PL协同设计

    https://blog.csdn.net/Fei_Yang_YF/article/details/79676172 什么是PS和PL ZYNQ-7000是Xilinx推出的一款全可编程片上系统(Al ...

  7. 1:httpd-2.2基础

    在配置httpd主配置文件时,应该先记得备份一下: #cd /etc/httpd/conf/ #cp httpd.conf{,.bak} #vim /etc/httpd/conf/httpd.conf ...

  8. HDU 5919 Sequence II(主席树+区间不同数个数+区间第k小)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5919 题意:给出一串序列,每次给出区间,求出该区间内不同数的个数k和第一个数出现的位置(将这些位置组 ...

  9. fee photo

    别样网 pexels Gratisography picjumbo lifeofpix foodiesfeed    

  10. 【三十四】thinkphp之curd操作

    1.数据创建(create) 接受提交过来的数据,比如表单提交的 POST(默认)数据.接受到数据后,还可以对数据进行有效的验证.完成.生成等工作 // 这里 create()方法就是数据创建,数据的 ...