当前位置:网站首页>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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
边栏推荐
- @GetMapping、@PostMapping、@PutMapping、@DeleteMapping的区别
- Database auditing - an essential part of network security
- CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
- 停止使用 Storyboards 和 Interface Builder
- Rasa 3.x 学习系列- Rasa - Issues 4792 socket debug logs clog up debug feed学习笔记
- markdown语法
- Introduction to resubmit Progressive Anti-Duplicate Submission Framework
- HCIP(17)
- 程序员常说的“左手锟斤拷,右手烫烫烫”是怎么回事?
- Jmeter secondary development to realize rsa encryption
猜你喜欢
随机推荐
Swift中的类型相关内容
用大白话解释“什么是ERP?” 看完这篇就全明白了
scala 集合通用方法
微信小程序(一)
数据库审计 - 网络安全的重要组成部分
机器学习-特征映射方法
Connect the Snowflake of CKAN tutorial CKAN to release to open data portal
厌倦了安装数据库?改用 Docker
华为设备配置BFD与接口联动(触发与BFD联动的接口物理状态变为Down)
CKAN教程之在 AWS 上部署 CKAN 应用程序
2022 Shandong International Youth Eye Health Industry Exhibition, Vision Health Exhibition, Optometry Exhibition
matplotlib中的3D绘图警告解决:MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure
I have been in the software testing industry for nearly 20 years, let me talk to you about today's software testing
Rasa 3.x 学习系列- Rasa - Issues 4792 socket debug logs clog up debug feed学习笔记
21天学习挑战赛(1)设备树的由来
Database auditing - an essential part of network security
js基础知识整理之 —— Date和定时器
最近公共祖先(LCA)学习笔记 | P3379 【模板】最近公共祖先(LCA)题解
2022暑假牛客多校1 (A/G/D/I)
Directing a non-relational database introduction and deployment








