Kotlin syntax for LiveData observer?

前端 未结 3 1807
失恋的感觉
失恋的感觉 2021-01-01 10:05

I have the following bit of code in my HomeActivity to use LiveData.

override fun onCreate(savedInstanceState: Bundle?) {
    sup         


        
3条回答
  •  隐瞒了意图╮
    2021-01-01 10:28

    To omit the Observer { ... } part just add import androidx.lifecycle.observe and use it like this:

    this.viewModel.user.observe(this) { user: User? ->
        // ...
    }
    

提交回复
热议问题