Reputation: 969
I have an image button and I want to be disabled when the program starts and upon certain condition, it needs to be enabled.
Here is my code,
public Screen( ) { //constructor
ImageButton hints;
ImageButton.ImageButtonStyle hintsstyle = new ImageButton.ImageButtonStyle();
hintsstyle.up = skin.getDrawable("newrightbut");
hintsstyle.down = skin.getDrawable("newrightbut");
hintsstyle.pressedOffsetX = 1;
hints = new ImageButton(hintsstyle);
hints.setPosition(650, 35);
hints.setHeight(70);
hints.setWidth(70);
stage.addActor(hints);
hints.setTouchable(Touchable.disabled);
}
public void update() {
hints.setTouchable(Touchable.enabled);
}
But, the button is not getting disabled when the program starts and I even tested with button.setDisabled(true) method. It also doesn't work. Any idea why? Any help would be great!! Thanks
Upvotes: 2
Views: 1233
Reputation: 1067
This issue is 5 months old now but I try to answer regardless.
ImageButton hints
is declared within your constructor (So its scope is limited to the constructor).
The only way that you don't get a compilation error calling it from a method outside the constructor is if you have also declared it somewhere else within your class.
Conclusion: you must have declared it somewhere else in your application and any default, it is enabled.
Upvotes: 0