当前位置:网站首页>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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
边栏推荐
猜你喜欢

高数---二重积分

记一次mysql查询慢的优化历程

CKAN教程之在 AWS 上部署 CKAN 应用程序

【斯坦福计网CS144项目】Lab5: NetworkInterface

1 - vector R language self-study

解决错误:Optional int parameter ‘pageSize‘ is present but cannot be translated into a null value due to

在软件测试行业近20年的我,再来和大家谈谈今日的软件测试

KubeSphere监控失效为NAN的问题

I have been in the software testing industry for nearly 20 years, let me talk to you about today's software testing

【系统架构设计师】第三章 数据库系统
随机推荐
秒懂网络拓扑中的下一跳地址
js基础知识整理之 —— 全局作用域
d实验新异常
IDEA 重复代码的黄色波浪线取消设置
Find My技术|智能防丢还得看苹果Find My技术
NLP常用Backbone模型小抄(1)
十年架构五年生活-04第一个工作转折点
即席查询—— Kylin使用
# DWD层及DIM层构建## ,220801 ,
最新真实软件测试面试题分享,收藏了还怕进入不了大厂?
CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
测试人生 | 阿里实习 90 天:从实习生的视角谈谈个人成长
js基础知识整理之 —— Date和定时器
主流定时任务解决方案全横评
解决错误:Optional int parameter ‘pageSize‘ is present but cannot be translated into a null value due to
Jmeter二次开发实现rsa加密
I have been in the software testing industry for nearly 20 years, let me talk to you about today's software testing
VMware workstation program starts slowly
用了TCP协议,就一定不会丢包吗?
KubeSphere监控失效为NAN的问题