当前位置:网站首页>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
边栏推荐
猜你喜欢

OneFlow学习笔记:从Functor到OpExprInterpreter

洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別

Use of Arthas in JVM tools

Knowledge points and problem solutions related to information collection

LaTeX论文排版操作

STM32 uses Hal library. The overall structure and function principle are introduced

《深度学习》学习笔记(八)

测试你的机器学习流水线

2022-04-22 OpenEBS云原生存储

Study notes of deep learning (8)
随机推荐
idea打包 jar文件
JVM工具之Arthas使用
ONEFLOW learning notes: from functor to opexprinter
微信:获取单个标签所有人
洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
Consensus Token:web3.0生态流量的超级入口
Failed to prepare device for development
是否完全二叉搜索树 (30 分)
Notes on 30 steps of introduction to Internet of things of yangtao electronics STM32 III. Explanation of new cubeide project and setting
Stm32f103zet6 [development of standard library functions] - Introduction to library functions
洋桃电子STM32物联网入门30步笔记一、HAL库和标准库的区别
swagger文档导出自定义v2/api-docs拦截
lgb,xgb,cat k折交叉验证
使用flask和h5搭建网站/应用的简要步骤
正点原子携手OneOS直播 OneOS系统教程全面上线
在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
ESP32程序下载失败,提示超时
匿名类型(C# 指南 基础知识)
Go语言自学系列 | golang方法
Ajax cache prevention method