lsaffie
lsaffie

Reputation: 1814

Set button action in controller

I have a navigation view with one button in the toolbar. Based on the view pushed, the button's label and functionality should chang. I've managed to do this by creating many buttons and activating them as needed (hide/show)

Instead of doing that approach I'd like to have just one button and in the controller change the text and action. Something along these lines:

this.getButton().setHtml("new text");
this.getButton().action = "newaction";

setHtml works, but setting the action doesn't. Examining the button in the console, I see the action changes but when I click it, it responds to the previous action.

Any suggestions on how to approach this?

Thanks

Upvotes: 0

Views: 1019

Answers (1)

rixo
rixo

Reputation: 25001

You should use setText instead of setHtml that, err... Doesn't seem to exist! And setHandler to change the handler function.

Alternatively, since you say that you're working in a controller, you can attach a function to the click event of the button and, inside this listener function, decide what action to execute in the current context.

Upvotes: 1

Related Questions