View Binding 和 Data Binding 是 Android 功能,用于比旧的 findViewById 更安全、更方便的方式将代码连接到 XML 布局中的视图。View Binding 提供类型安全的视图引用;Data Binding 还可以将数据直接绑定到布局。
问题:findViewById
The old way: findViewById to get view references:
val button = findViewById<Button>(R.id.myButton)
✗ verbose; NOT type-safe (cast errors); NOT null-safe (wrong id → null → crash at runtime)
→ View/Data Binding solve these.
