当前位置:网站首页>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
边栏推荐
- 信息收集相关知识点及题解
- rembg 分割mask
- Illegal character in scheme name at index 0:
- On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
- What is RPC
- SYS_ CONNECT_ BY_ Path (column, 'char') combined with start with connect by prior
- 还原二叉树 (25 分)
- Swagger document export custom V2 / API docs interception
- PgSQL wants to implement all kinds of column sub query operations of MySQL
- Yangtao electronic STM32 Internet of things introduction 30 steps notes 1. The difference between Hal library and standard library
猜你喜欢

RCC introduction of Hal Library

After a circle, I sorted out this set of interview questions..

Harbor企业级镜像管理系统实战

ONEFLOW learning notes: from functor to opexprinter

SYS_CONNECT_BY_PATH(column,'char') 结合 start with ... connect by prior

Get the absolute path of the class according to the bytecode

测试你的机器学习流水线

'bully' Oracle enlarged its move again, and major enterprises deleted JDK overnight...

Redis Desktop Manager for Mac(Redis可视化工具)

让地球少些“碳”息 度能在路上
随机推荐
Notes on 30 steps of introduction to Internet of things of yangtao electronics STM32 III. Explanation of new cubeide project and setting
正点原子携手OneOS直播 OneOS系统教程全面上线
Record: JS several methods to delete one or more items in the array
L2-3 浪漫侧影 (25 分)
DOM learning - add + - button
洋桃电子STM32物联网入门30步笔记二、CubeIDE下载、安装、汉化、设置
Misunderstanding of flush () method of OutputStream class
LINQ学习系列-----1.4 匿名对象
Word plus watermark
PgSQL wants to implement all kinds of column sub query operations of MySQL
完全二叉搜索树 (30 分)
微信:获取单个标签所有人
Copy array in JS
关于cin,scanf和getline,getchar,cin.getline的混合使用
1099 establish binary search tree (30 points)
JSP page coding
【精品】利用动态代理实现事务统一管理 二
Ajax cache prevention method
tsdf +mvs
Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing