当前位置:网站首页>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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
边栏推荐
- What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
- 买母婴产品先来京东“券民空间站”抢券!大牌好物低至5折
- LVM与磁盘配额原理及配置
- 最近公共祖先(LCA)学习笔记 | P3379 【模板】最近公共祖先(LCA)题解
- No-code development platform form styling steps introductory course
- 基于奇异谱分析法和长短时记忆网络组合模型的滑坡位移预测
- markdown语法
- 我们来浅谈代码语言的魅力
- 如何使用vlookup+excel数组公式 完成逆向查找?
- 基于飞腾平台的嵌入式解决方案案例集 1.0 正式发布!
猜你喜欢

What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?

CTF命令执行题目解题思路

基于STM32设计的老人防摔倒报警设备(OneNet)

高数---二重积分

js基础知识整理之 —— 判断语句和三元运算符

MySQL最大建议行数2000w, 靠谱吗?

微信小程序(一)

我们来浅谈代码语言的魅力

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

Cholesterol-PEG-Amine,CLS-PEG-NH2,胆固醇-聚乙二醇-氨基脂两亲性脂质衍生物
随机推荐
threejs dynamically adjust the camera position so that the camera can see the object exactly
Canonical correlation analysis of CCA calculation process
Jmeter secondary development to realize rsa encryption
测试人生 | 阿里实习 90 天:从实习生的视角谈谈个人成长
js基础知识整理之 —— 五种输出方式
What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
Database auditing - an essential part of network security
pytest-常用运行参数
Connect the Snowflake of CKAN tutorial CKAN to release to open data portal
十年架构五年生活-05第一次出差
Pytest配置项-pytest.ini
Nlog自定义时间
Directing a non-relational database introduction and deployment
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
CAS:474922-22-0,DSPE-PEG-MAL,磷脂-聚乙二醇-马来酰亚胺科研试剂供应
我们来浅谈代码语言的魅力
用了这么多年的LinkedList,作者说自己从来不用它?为什么?
HCIP(17)
DataGuard日常维护常见问题之数据同步异常
nmap: Bad CPU type in executable