Salvador Hernandez
Salvador Hernandez

Reputation: 309

Android - need to implement two switches that can turn each other on and off

I have two switches A and B. Thus far I can get it so that when A is on, and I tap on it, it can go to off, and switch B to on. But if I try to initiate A to on, or B to on from off, then I can't do it. Is there a simple elegant way in which they both can talk to each other. I have already used onCheckChanged and onClickListener to implement a logic for this. Any help would be great.

Upvotes: 0

Views: 217

Answers (2)

touchofsarcasm
touchofsarcasm

Reputation: 79

I used onCheckChanged and it worked just fine. You just use setChecked(boolean)

Here's my example: MainActivity.java

activity_main.xml

Upvotes: 1

usmanzk
usmanzk

Reputation: 21

You can use radioButtons . Here's a link

Upvotes: 1

Related Questions