I'm trying to make a pretty iPhone toggle button and stumbled upon this code from a generous StackOverflow user. So I basically cleaned up the example code until I'm left with what I need; one toggle button;
Everything works as expected, but the only thing that I don't know how to reverse the sides of the button. Currently, if the toggle is on the left side it means true
, and the right side means false
. I of course changed the wording, but that doesn't change the resulting boolean. I can of course also change my code to do the necessary stuff when it's false instead of true, but this would make our code totally unreadable.
I suppose I need to change something in this file, but in there I'm kinda lost. Would anybody know what I need to do to reverse the sides of the button?
===EDIT===
With the line toggleButton.setOnCheckedChangeListener(this);
I set the listener to this method:
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d(TAG,"onChechedChanged(checked = "+isChecked+")");
if (isChecked){
doSomeStuffHere();
}
else {
doNothingHere();
}
}
Again, I can of course simply reverse the doSomeStuffHere() and doNothingHere() or even reverse the boolean before that if-statement, but that would make my code not very nice. I just want it to be correct from a coding perspective.