当前位置:网站首页>2.9 overview of databinding knowledge points
2.9 overview of databinding knowledge points
2022-07-03 12:15:00 【schr03p】
There may only be one right , There are thousands of mistakes .
One 、 Basic usage
Enable
dataBinding
// stay module Of build.gradle in
apply plugin: 'kotlin-kapt'// must
android{
//AS 4.0 following ,
dataBinding{
enabled true
}
//AS 4.1 after
bindingFeature{
dataBinding = true
// for view binding :
// viewBinding = true
}
}UIreform
<layout>
<data class="">
</data>
<!-- The original UI Of xml Layout in layout Just inside the label .data Label memory for xml Data variables for , type -->
<LinearLayout>
</LinearLayout>
</layout>viewBindinganddataBindingxmlData types invariableDeclare variables ;importImport type ; aboutxmlSpecial symbols of need escape similar&binding
xmlAnddataFormat :@{}、@={}( Two way binding )Available expressions 、 Function call 、 Property parameters
??Sentenced to empty?:Ternary operator@string/str_nameResource Citation , Available placeholdersformat+Concatenate characters , Use `` The quotation marksdefaultSet the default valueincludebindingClick event
οnclick="@{()->vm.click()}" οnclick="@{(v)->vm.click(v)}" οnclick="@{()->vm.click(context)}" οnclick="@{BindHelp::staticClick}" οnclick="@{callback}"EditTextTwo-way binding oftext="@={etStr}"UIMiddle AssociationxmlOfdataBinding
//activity in val binding = DataBindingUtil.setContentView<ActivityBaseUseBinding>(this, R.layout.activity_base_use) //fragment in xxxBinding.inflater()
Two 、 Advanced usage
android:onCheckedChanged="@{(switch,checked)->vm.broadcast(checked)}"Binding Respond to
UIOfdata BeanAdapterAdapter for list ,include@BindingConversionTransformation support@BindingAdapterAdvanced support@InverseBindingAdapterInverse binding@bindingadapter(xxx)
@bindingadapter(xxxAttrChanged)
@inverseBindingadapter
@BindingMethodsAdaptation extension supportbindingFunction of
Experience of pit :
TextViewOftextattribute , Have its attentiondataNot forNumbertypexmlChinese characters cannot be ChineseReflection attribute 、 The function must be
publicUse
liveDataAsdataBindingWhen , Bear in minduiSet inbinding.lifecycleOwnerobservableFieldData time , Some occasions require initialization , Otherwise, an error is reported during operation , It's not easy to checkIDEDevelopment to avoid character collapse caused by Chinese input method , especiallyxmlin ../gradlew app:build,./gradlew app:dependenciesetc.gradleThe instructions of are often , It's easy to make mistakes--stacktrace --debugAnd other necessary parameters , UseExecution failed for taskBuild error messages .clean,rebuild,clear cache,delete build and apk Folderbuild.gradle,--offline,AS&gradle Version match for
边栏推荐
- Vulnhub's cereal
- 232. Implement queue with stack
- Capturing and sorting out external Fiddler -- Conversation bar and filter [2]
- Integer int compare size
- 102. Sequence traversal of binary tree
- DNS multi-point deployment IP anycast+bgp actual combat analysis
- vulnhub之Ripper
- Simple factory and factory method mode
- Vulnhub geminiinc
- 4000字超详解指针
猜你喜欢

Shutter: add gradient stroke to font

PHP导出word方法(一phpword)

Duplicate numbers in the array of sword finger offer 03

Kubernetes three dozen probes and probe mode

(construction notes) ADT and OOP

Itext7 uses iexternalsignature container for signature and signature verification

LeetCode 0556.下一个更大元素 III - 4步讲完

Symlink(): solution to protocol error in PHP artisan storage:link on win10

Shutter: overview of shutter architecture (excerpt)

"Jianzhi offer 04" two-dimensional array search
随机推荐
CGroup introduction
Vulnhub's cereal
OpenGL 着色器使用
为什么我的mysql容器启动不了呢
SLF4J 日志门面
Pragma pack syntax and usage
DEJA_ Vu3d - cesium feature set 053 underground mode effect
Develop plug-ins for idea
(construction notes) grasp learning experience
Introduction to concurrent programming (I)
Jsup crawls Baidu Encyclopedia
Flutter 退出登录二次确认怎么做才更优雅?
Shardingsphere sub database and sub table < 3 >
SystemVerilog -- OOP -- copy of object
Fluent: Engine Architecture
New features of ES6
Flutter Widget : KeyedSubtree
安装electron失败的解决办法
Unicode encoding table download
(构造笔记)GRASP学习心得