1.使用DataBindingLibrary  在layout中 绑定 UI 和 数据

仅适用:(1)单项绑定(@{entity.name})   数据   ——> UI

              (2)双向绑定(@={entity.name})  数据 <——> UI

entity中仅适用成员变量和默认生成的get/set方法,构造方法

android UI和数据

2.ViewModel 存储管理与UI相关的数据(绝对不能持有任何view,声明周期和对context有引用的类)

3.LiveData仅更新处于活动周期状态的应用组件

(1)UI需要用到的数据,都放到viewModel

android UI和数据

4.MainActivity中使用

android UI和数据

android UI和数据

 

相关文章:

  • 2021-11-25
  • 2021-10-22
  • 2022-02-24
  • 2021-08-14
  • 2021-08-26
  • 2021-11-30
  • 2022-02-15
  • 2021-12-27
猜你喜欢
  • 2022-01-21
  • 2022-12-23
  • 2021-11-29
  • 2022-01-27
  • 2021-06-21
  • 2021-10-27
相关资源
相似解决方案