Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to know which better spinner is selected or clicked #99

Open
jellybins opened this issue Jan 16, 2019 · 2 comments
Open

how to know which better spinner is selected or clicked #99

jellybins opened this issue Jan 16, 2019 · 2 comments

Comments

@jellybins
Copy link

how to know which better spinner is selected or clicked
when there are two or more beeterspinner widgets and they use a same onItemClickListener

@enoquesantos
Copy link

You can try this:

        // code in Kotlin
        MaterialBetterSpinner spinner = findViewById(R.id.material_better_spinner)

        // add a listener to each spinner
        spinner.addTextChangedListener(object : TextWatcher {
            override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
                val optionSelected = s.toString().toLowerCase()

                showToast("Ok. Option selected was $optionSelected")
            }

            override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, aft: Int) {}

            override fun afterTextChanged(s: Editable) {}
        })

@pablin202
Copy link

pablin202 commented May 23, 2019

You can use this extension function:

fun EditText.afterTextChanged(afterTextChanged: (String) -> Unit) { this.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { } override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { } override fun afterTextChanged(editable: Editable?) { afterTextChanged.invoke(editable.toString()) } }) }

then:
spinner.afterTextChanged { toast(it) }

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

No branches or pull requests

3 participants