Created
November 13, 2019 00:23
-
-
Save sergeich/62f39294282b56e37f08319b15c1c002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ParamViewModel( | |
someParameter: Int | |
) : ViewModel() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeActivity : FragmentActivity() { | |
private lateinit var viewModel: ParamViewModel | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
val param = 42 | |
val factory = ParamViewModelFactory(param) | |
viewModel = ViewModelProviders.of(this, factory).get(ParamViewModel::class.java) | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ParamViewModelFactory( | |
private val someParameter: Int | |
) : ViewModelProvider.NewInstanceFactory() { | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
return ParamViewModel(someParameter) as T | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment