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

switch button not have On Click Listener #30

Open
AbdElRahmanJamal opened this issue Aug 16, 2018 · 2 comments
Open

switch button not have On Click Listener #30

AbdElRahmanJamal opened this issue Aug 16, 2018 · 2 comments

Comments

@AbdElRahmanJamal
Copy link

@OverRide
public final void setOnClickListener(OnClickListener l) {}

can you please add its implementation

@JobGetabu
Copy link

switch.setOnTouchListener { _, event ->
            if (event.action == MotionEvent.ACTION_UP) {
                // Do what you want
                true
            } else false
        }

@khaled-qawafel
Copy link

khaled-qawafel commented Dec 14, 2021

If you want to use "switch.isChecked" boolean in a listener you can use @JobGetabu and wrap the switch in a ViewGroup so that you can use "switch.isChecked" in it's listener like this

switch.setOnTouchListener { _, event ->
            if (event.action == MotionEvent.ACTION_UP) {
                switchWrapper.performClick()
            true
        }

switchWrapper.setOnClickListener {
val newSwitchStatus = status.isChecked().not()
if (newSwitchStatus)
// Do what you want
status.isChecked() = newSwitchStatus
}

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