'How to fill the spinner with a custom object with coroutines and implement your onItemSelected logic related to that object?
For example, let's use this class:
data class Person (
var id : Long,
var name: String,
var imageUrl: String
)
I need to fill my spinner with name
values from the custom objects of Person
, and when some value is selected in spinner, I need to update the image according to the imageUrl
in the selected object.
Is there any other way to make that than overriding toString() function in Person? For example, if I have to use Person class somewhere else where I need another toString implementation
Also I'm getting the List of Persons from api/room through kotlin coroutines
private fun collectFlows(){
lifecycleScope.launchWhenStarted {
repeatOnLifecycle(Lifecycle.State.STARTED){
mainViewModel.personStateFlow.collectLatest {
// update adapter's list
}
}
}
}
so how to always update the list in adapter when it changes? I know how to make it with custom adapter for RecyclerView, but I'm confused about how to make such thing with spinner adapter.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|