What I would do is keep flags for each state at the class level, for example:
public class MyClass {
private static final int STATE_SAVE = 0;
private static final int STATE_DISPLAY = 1;
private int currentState = STATE_DISPLAY;
}
Then inside the toggle button you can set a flag. To paraphrase this code, since I do not have an open editor:
toggleButton.setOnToggleListener(new OnToggleListener() {
@Override
public void onToggled(boolean toggled) {
if(toggled) {
currentState = STATE_SAVE;
} else {
currentState = STATE_DISPLAY;
}
});
Now that the buttons are pressed, you can switch to the state to perform the action:
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(currentState == STATE_SAVE) {
} else if (currentState == STATE_DISPLAY) {
}
});
source
share