当前位置:网站首页>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
边栏推荐
猜你喜欢
增强现实技术是什么?能用在哪些地方?
测试你的机器学习流水线
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
K210 learning notes (II) serial communication between k210 and stm32
JVM工具之Arthas使用
Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
2022-04-22 OpenEBS云原生存储
MATLAB 画五星红旗
Test your machine learning pipeline
正点原子携手OneOS直播 OneOS系统教程全面上线
随机推荐
匿名類型(C# 指南 基礎知識)
ajax防止缓存方法
xctf刷题小记
PgSQL wants to implement all kinds of column sub query operations of MySQL
关于堆的判断 (25 分) 两种插入方式
Shell脚本进阶
Introduction to protobuf
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
php基于哈希算法出现的强弱比较漏洞
LaTeX数学公式
虚拟线上展会-线上vr展馆实现24h沉浸式看展
SYS_ CONNECT_ BY_ Path (column, 'char') combined with start with connect by prior
Large amount of data submitted by form post
LINQ Learning Series ----- 1.4 anonymous objects
完全二叉搜索树 (30 分)
00后最关注的职业:公务员排第二,第一是?
MATLAB 画五星红旗
Yangtao electronic STM32 Internet of things entry 30 step notes II. Cube ide download, installation, sinicization and setting
Go语言自学系列 | golang结构体指针
Navicat远程连接mysql