Android app 101
First Application
- different views
- layout
- event handler
- data binding
- help app no need to initialize the variable each time, which can save time.
- findViewById() find view will create or recreate when it is called.
- It is a global technology for the whole app, like a reference.
- how to use it
- enable data binding in your build.gradle file
1
2
3
4
5android {
buildFeatures {
dataBinding true
}
} - sync your application
- move the namespace declaration into layout tag and just keep view properties
- declare a binding variable for binding the specific layout which you have defined a layout tag. Then using the following code to set data to data binding
1
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
- replace the findViewById to binding.idView
- enable data binding in your build.gradle file
- bind string value from a
data
class
source code
- Title: Android app 101
- Author: Xiao Qiang
- Created at : 2023-03-05 14:48:07
- Updated at : 2025-03-08 10:49:30
- Link: http://fdslk.github.io/tech/kotlin/Android/2023/03/05/Android-app-101/
- License: This work is licensed under CC BY-NC-SA 4.0.
Comments