当前位置:网站首页>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 } }
UI
reform
<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>
viewBinding
anddataBinding
xml
Data types invariable
Declare variables ;import
Import type ; aboutxml
Special symbols of need escape similar&
binding
xml
Anddata
Format :@{}
、@={}
( Two way binding )Available expressions 、 Function call 、 Property parameters
??
Sentenced to empty?:
Ternary operator@string/str_name
Resource Citation , Available placeholdersformat
+
Concatenate characters , Use `` The quotation marksdefault
Set the default valueinclude
bindingClick event
οnclick="@{()->vm.click()}" οnclick="@{(v)->vm.click(v)}" οnclick="@{()->vm.click(context)}" οnclick="@{BindHelp::staticClick}" οnclick="@{callback}"
EditText
Two-way binding oftext="@={etStr}"
UI
Middle Associationxml
OfdataBinding
//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
UI
Ofdata Bean
Adapter
Adapter for list ,include
@BindingConversion
Transformation support@BindingAdapter
Advanced support@InverseBindingAdapter
Inverse binding@bindingadapter(xxx)
@bindingadapter(xxxAttrChanged)
@inverseBindingadapter
@BindingMethods
Adaptation extension supportbinding
Function of
Experience of pit :
TextView
Oftext
attribute , Have its attentiondata
Not forNumber
typexml
Chinese characters cannot be ChineseReflection attribute 、 The function must be
public
Use
liveData
AsdataBinding
When , Bear in mindui
Set inbinding.lifecycleOwner
observableField
Data time , Some occasions require initialization , Otherwise, an error is reported during operation , It's not easy to checkIDE
Development to avoid character collapse caused by Chinese input method , especiallyxml
in ../gradlew app:build
,./gradlew app:dependencies
etc.gradle
The instructions of are often , It's easy to make mistakes--stacktrace --debug
And other necessary parameters , UseExecution failed for task
Build error messages .clean,rebuild,clear cache,delete build and apk Folder
build.gradle,--offline
,AS&gradle Version match for
边栏推荐
- 145. Post order traversal of binary tree
- Introduction to the implementation principle of rxjs observable filter operator
- Raven2 of vulnhub
- Vulnhub's cereal
- 242. Effective letter heteronyms
- Interview experience in summer camp of Central South University in 2022
- 抓包整理外篇fiddler———— 会话栏与过滤器[二]
- (构造笔记)MIT reading部分学习心得
- Differences between MySQL Union and union all
- Integer int compare size
猜你喜欢
随机推荐
Fundamentals of concurrent programming (III)
OpenGL draws colored triangles
Flutter 退出登录二次确认怎么做才更优雅?
C language improvement article (wchar_t) character type
PHP export word method (one MHT)
DEJA_VU3D - Cesium功能集 之 053-地下模式效果
Xiaopeng P7 hit the guardrail and the airbag did not pop up. The official responded that the impact strength did not meet the ejection requirements
抓包整理外篇fiddler———— 会话栏与过滤器[二]
Differences between MySQL Union and union all
Redis
257. All paths of binary tree
vulnhub之Nagini
OpenGL 索引缓存对象EBO和线宽模式
20. Valid brackets
DEJA_VU3D - Cesium功能集 之 054-模拟火箭发射全过程
QT OpenGL rotate, pan, zoom
Simple factory and factory method mode
145. Post order traversal of binary tree
4000 word super detailed pointer
Basic knowledge of OpenGL (sort it out according to your own understanding)