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. Flask学习【第4篇】:用Flask的扩展实现的简单的页面登录

    from flask import Flask,render_template,request,redirect,session app = Flask(__name__,template_folde ...

  2. php的pear编程: phpDocumentor的使用?

    pfc: php基础类库: pecl: php扩展公共库 pear: php extension and application repository. php的扩展和应用库 phar: ['fa:] ...

  3. Hyper

    https://github.com/zeit/hyper https://gist.github.com/coco-napky/404220405435b3d0373e37ec43e54a23 Ho ...

  4. Match function in R

    Examples:     print(match(5, c(1,2,9,5,3,6,7,4,5)))[1] 4     5 %in% c(1,2,9,5,3,6,7,4,5)[1] TRUE    ...

  5. ffmpeg 下载安装和简单应用

    一.ffmpeg下载 先到http://ffmpeg.org/下载ffmpeg安装文件 二.ffmpeg安装 1.解压下载完的ffmpeg-20190319-f8075b2-win64-shared. ...

  6. c# 重试机制

    protected async Task<T> TryOperation<T>(int maxRetryCount,Func<Task<T>> func ...

  7. SQLite EF Core Database Provider

    原文链接 This database provider allows Entity Framework Core to be used with SQLite. The provider is mai ...

  8. Footnotes for tables in latex - 为latex的table加上footnotes

    参考: Footnotes for tables in LaTeX Footnote in tabular environment Footnotes for tables in latex - 为l ...

  9. 完美解决百度网盘、浏览器下载限速问题proxyee-down(附带win破解版云盘)

    win版破解云盘 下载: <PanDownload> 使用文档: <PanDownload使用> Mac方法 限速.限速! 平时下载东西限速倒无所谓,遇到急一点的.盯着80km ...

  10. 【BZOJ】3926: [Zjoi2015]诸神眷顾的幻想乡

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3926 广义后缀自动机... 久仰公之大名啊... 太阳花田的结构比较特殊,只与一个空地相邻 ...