[英]Why am i getting this error when trying to Implement ViewModel?
I am trying to learn about ViewModels so i am following the instructions from the Android Developer docs, but unfortunately I am receiving this message i attached a screenshot.我正在尝试了解 ViewModels,所以我按照 Android 开发人员文档中的说明进行操作,但不幸的是,我收到了这条消息,我附上了截图。 All I have really done so far was added necessary implementations stated on the website and followed what was stated on the doc to implement it.
到目前为止,我所做的只是添加了网站上说明的必要实现,并按照文档中的说明来实现它。
def lifecycle_version = "2.6.0-alpha02"
def arch_version = "2.1.0"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
//Was not recognizing ViewModelProvider so i added this to fix it..
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
Add second parameter ViewModelFactory in ViewModelProvider在 ViewModelProvider 中添加第二个参数 ViewModelFactory
val factory = YourViewModelFactory(YourRepository())
viewModel = ViewModelProvider(this, factory).get(yourViewModelclass::class.java)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.