Skip to content

Instantly share code, notes, and snippets.

@fayaz07
Created September 3, 2022 01:30
Show Gist options
  • Save fayaz07/c9b5f73509354e012bb7a2db62a54f50 to your computer and use it in GitHub Desktop.
Save fayaz07/c9b5f73509354e012bb7a2db62a54f50 to your computer and use it in GitHub Desktop.
class MViewModelFactory(private val todoDao: TodoDao) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return when(modelClass) {
MainViewModel::class.java -> {
MainViewModel(todoDao) as T
}
CreateViewModel::class.java -> {
CreateViewModel(todoDao) as T
}
else -> {
throw IllegalStateException()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment