Skip to content

Instantly share code, notes, and snippets.

@rommansabbir
Created February 14, 2021 20:02
Show Gist options
  • Save rommansabbir/3354b8e5b7da3a939f6f99e3c804495d to your computer and use it in GitHub Desktop.
Save rommansabbir/3354b8e5b7da3a939f6f99e3c804495d to your computer and use it in GitHub Desktop.
inline fun Spinner.onItemSelectedListenerCustom(crossinline changed: (AdapterView<*>?, View?, Int, Long) -> Unit): AdapterView.OnItemSelectedListener {
val listener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
changed.invoke(parent, view, position, id)
}
override fun onNothingSelected(parent: AdapterView<*>?) {}
}
this.onItemSelectedListener = listener
return listener
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment