I want to add a spinner
to my toolbar
. When researching I found a lot of different ways on how to do this, however the newest were about 4 years old and the solutions I found did not feature kotlin. Since kotlin is the "standard" nowadays I am wondering, what is the preferred way of doing this today? Or is there even a preferred way?
I don't think anything much has changed in 4 years - the Material version of a Spinner is an Exposed Dropdown Menu which seems to be "pretend a TextView
works like an Adapter
" and is a real pain if you just want to know item 2 was selected or whatever. All having to implement "text changed" callbacks and look at what the text is now, what does that correspond to, etc
Have you looked at the Android documentation? That's pretty much all there is to it, I don't think you need to do anything special so long as you're adding your own Toolbar
to layouts instead of using the old system one. It's just another view in your layout.
Kotlin doesn't seem to bring anything new to it, apart from the syntax being a bit nicer for some things. You still have to implement a two-method callback interface for the Adapter
so you can't use a nice simple lambda or anything