ToggleButton state change programmatically rather than automatically in Android?
Asked Answered
S

1

9

I have created a custom class which extends ToggleButton and I override the toggle method and do not do anything in that. This has helped me in having control of switching togglebutton from on to off. Is this proper way of doing?

I wanted to have the control of togglebutton switching. I mean it should go from on to off based on certain conditions otherwise it should remain in the state it was.

This way its working but want to know whether its the correct way of doing or not.

Subscript answered 18/2, 2011 at 11:59 Comment(0)
F
6

What you are looking for is ToggleButton.setChecked.

Felicity answered 18/2, 2011 at 12:6 Comment(3)
Yes, but if we just use setChecked based on certain condition then togglebutton do not behave properly. For eg, say togglebutton state is false and then I click it, immediately goes to true. Now, if based on conditions its state should be false only then it will again change its state to false. So there will be switch from true to false. What I want is it should remain to false only.Subscript
That's not how a standard ToggleButton works. You'll have to create your own. You can do this for example by inheriting the Button class and implementing the state changes.Felicity
Well, that's what I have done by inheriting the ToggleButton class and overriding the toggle method. I don't do anything in toggle method and then I can set its state as I want.Subscript

© 2022 - 2024 — McMap. All rights reserved.