当前位置:网站首页>dataBinding的import导入
dataBinding的import导入
2022-08-02 23:22:00 【锐湃】
1>main_sub.xml
<?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"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="user"
type="com.lxk.databindingtest.UserInfo" />
<import type="com.lxk.databindingtest.StarUtils"/>
<variable
name="butt"
type="com.lxk.databindingtest.ButtonClickListener" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="@{StarUtils.getStar(user.star)}"
tools:text="一星" />
<TextView
android:id="@+id/textView"
android:layout_width="46dp"
android:layout_height="19dp"
tools:text="姓名"
android:text="@{user.name}"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="加分"
android:onClick="@{butt.likeClick}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
2>main.xml导入main_sub.xml
<?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"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="userInfo"
type="com.lxk.databindingtest.UserInfo" />
<variable
name="buttClick"
type="com.lxk.databindingtest.ButtonClickListener" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
layout="@layout/main_sub"
app:user="@{userInfo}"
app:butt="@{buttClick}"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
3>MainActivity
public class MainActivity extends AppCompatActivity {
ActivityMainBinding activityMainBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityMainBinding= DataBindingUtil.setContentView(this,R.layout.activity_main);
UserInfo userInfo=new UserInfo("于振锋",5);
activityMainBinding.setUserInfo(userInfo);
activityMainBinding.setButtClick(new ButtonClickListener(this));
}
}
作者:北京小强户外
链接:https://www.jianshu.com/p/5aae2167078b
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
边栏推荐
猜你喜欢
CAS:474922-22-0,DSPE-PEG-MAL,磷脂-聚乙二醇-马来酰亚胺科研试剂供应
公司招个程序员,34岁以上两年一跳的不要,开出工资以为看错了
js基础知识整理之 —— 五种输出方式
数据库审计 - 网络安全的重要组成部分
The latest real software test interview questions are shared. Are you afraid that you will not be able to enter the big factory after collecting them?
00 -- jieba分词
# DWD层及DIM层构建## ,220801 ,
6、Powershell命令配置Citrix PVS云桌面桌面注销不关机
CKAN教程之在 AWS 上部署 CKAN 应用程序
语音合成模型小抄(1)
随机推荐
Swift中的类型相关内容
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
IDEA多线程调试
Mock工具之Moco使用教程
思源笔记 本地存储无使用第三方同步盘,突然打不开文件。
js基础知识整理之 —— Math
用了 TCP 协议,数据一定不会丢吗?
如何使用vlookup+excel数组公式 完成逆向查找?
十年架构五年生活-03作为技术组长的困扰
C语言函数详解(2)【函数参数——实际参数(实参)&形式参数(形参)】
技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
vant-swipe自适应图片高度+图片预览
RollBack Rx Professional RMC 安装教程
NLP常用Backbone模型小抄(1)
最新真实软件测试面试题分享,收藏了还怕进入不了大厂?
HCIP(16)
HCIP(17)
用大白话解释“什么是ERP?” 看完这篇就全明白了
即席查询—— Kylin使用
2022暑假牛客多校1 (A/G/D/I)