当前位置:网站首页>Use include in databinding
Use include in databinding
2022-04-23 08:42:00 【Sharp surge】
DataBinding Next Use include Include transfer of objects , Event monitoring .
include The layout is as follows :
custom_home.xml
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:binding="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="user"
type="com.yc.bean.User" />
<variable
name="onImgClick "
type="android.view.View.OnClickListener" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick ="@{onImgClick }"
android:src="@mipmap/ic_home_position"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.name}"
android:textColor="@color/colorBarText"
android:textSize="12sp" />
</LinearLayout>
</Layout>
Here we use objects and monitor Words , You have to declare the corresponding variable
main.xml In the code :
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:binding="http://schemas.android.com/apk/res-auto">
<data>
<import type="com.yc.ui.home.HomeFragmentViewModel"/>
<variable
name="viewModel"
type="HomeFragmentViewModel" />
<variable
name="user"
type="com.yc.bean.User"/>
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
.......
<include android:id="@+id/include"
layout="@layout/custom_home"
binding:onImgClick ="@{viewModel.onImgClick}"
binding:user="@{user}"/>
</FrameLayout>
</layout>
binding:user=@{user}
here binding:include Middle variable name =@{ The listening or entity object passed in }
The name must correspond, or you can't find The class name must also be the same .
viewModel Medium method :
public View.OnClickListener onImgClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showShort(" Click on the avatar ");
}
};
————————————————
Copyright notice : This paper is about CSDN Blogger 「 Yunmeng Xinghe 」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/yunmengxinghe/article/details/107792376
版权声明
本文为[Sharp surge]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230835080560.html
边栏推荐
- STM32 uses Hal library. The overall structure and function principle are introduced
- 请问中衍期货安全靠谱吗?
- Get the absolute path of the class according to the bytecode
- LLVM之父Chris Lattner:编译器的黄金时代
- OneFlow學習筆記:從Functor到OpExprInterpreter
- idea配置连接远程数据库MySQL,或者是Navicat连接远程数据库失败问题(已解决)
- 匿名類型(C# 指南 基礎知識)
- Failed to convert a NumPy array to a Tensor(Unsupported Object type int)
- Input / output system
- bashdb下载安装
猜你喜欢
Idea import commons-logging-1.2 Jar package
GUI编程简介 swing
计算神经网络推理时间的正确方法
洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
RPC procedure
RPC过程
1099 establish binary search tree (30 points)
SYS_CONNECT_BY_PATH(column,'char') 结合 start with ... connect by prior
在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
随机推荐
Yangtao electronic STM32 Internet of things entry 30 step notes IV. engineering compilation and download
《深度学习》学习笔记(八)
2021李宏毅机器学习之Adaptive Learning Rate
How to generate assembly file
pgsql想实现mysql一样样的列子查询操作
php基于哈希算法出现的强弱比较漏洞
bashdb下载安装
请问中衍期货安全靠谱吗?
在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
关于数组复制问题
After a circle, I sorted out this set of interview questions..
Stm32f103zet6 [development of standard library functions] - Introduction to library functions
Introduction to protobuf
DOM learning - add + - button
PDF with watermark
Enctype attribute in form
完全二叉搜索树 (30 分)
Transformer XL: attention language modelsbbeyond a fixed length context paper summary
企业微信应用授权/静默登录
Notes on 30 steps of introduction to Internet of things of yangtao electronics STM32 III. Explanation of new cubeide project and setting