我想在 Dialog 中使用 mvvm 但我不知道如何通过LifecycleOwner
观察
class CommonDialog(context: Context) : Dialog(context, R.style.AppMaskStatusTheme) {
private val viewBinding: DialogSportOrderBinding by lazy { DialogSportOrderBinding.inflate(LayoutInflater.from(context)) }
private val viewModel by lazy { ViewModelProvider(context as ViewModelStoreOwner)[SportOrderViewModel::class.java] }
init {
setContentView(viewBinding.root)
viewModel.sportOrderList.observe(***what to pass here?***, androidx.lifecycle.Observer {
})
}
}
我试过了context as LifecycleOwner
,context as AppCompatActivity
但都失败了
请帮助我,谢谢!