Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

AdapterView on item selected listener #494

Closed
dovahkiin98 opened this issue Apr 12, 2018 · 1 comment
Closed

AdapterView on item selected listener #494

dovahkiin98 opened this issue Apr 12, 2018 · 1 comment

Comments

@dovahkiin98
Copy link

This will make settings selection listener easier, and it's still safe for onNothingSelected

fun AdapterView<*>.setOnItemSelectedListener(listener: (view: View?, position: Int, id: Long) -> Unit) {
        onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
            override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) =
                listener(view, position, id)

            override fun onNothingSelected(parent: AdapterView<*>) = listener(null, -1, 0)
        }
    }
@JakeWharton
Copy link
Contributor

Dupe of #470

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants