Getting a button bar to 'latch' on the pressed button

You must Login before you can answer or comment on any questions.

I have several button bars (created dynamically), each with their own event listeners (also created dynamically).

I want the button pressed to remain selected, but can't achieve this. I'm trying to do this by getting the index of the selected button, then setting the index of the button bar object. When I select a button, it is instantaneously selected, but then de-selects again.

Any ideas on how to get the button to stay selected?

2 Answers

It's not clear what you are trying to do with the button bars I.e where they are being placed.

To 'keep a button selected' simply change its background image to the same as the backgroundSelected state. There's no way to hold on to it, the event is fired and as soon as you stop pressing down the selectedBackground state is removed.. So cheat..

— answered 8 months ago by Mark Henderson
answer permalink
2 Comments
  • The button bars are just being placed on a window in a nav group. All I'm trying to do is get the pressed button to remain selected, i.e. highlighted blue.

    How do I capture an image of the background selected state?

    — commented 8 months ago by Ian Taylor

  • Well it's easier to create the image you want and set the selectedBackgroundImage property in the button declaration.. As long as the user can see which is the currently selected button that is usually good enough..

    — commented 8 months ago by Mark Henderson

Or you can do it with colours as well..

— answered 8 months ago by Mark Henderson
answer permalink
3 Comments
  • Wow, that seems like a lot of work for what I originally thought would be a basic option for a buttonbar.

    I don't think creating a background image is an option, as I create my buttonbars dynamically and don't know how many buttons they're going to have.

    Is it possible to change the colour of an individual button then? Would you mind providing some sample code on how to do this?

    — commented 8 months ago by Ian Taylor

  • I found the answer - as TabbedBar !

    — commented 8 months ago by Ian Taylor

  • Now I know what you meant! (Long day) screenshot would have got me there.. Happy coding!

    — commented 8 months ago by Mark Henderson

Your Answer

Think you can help? Login to answer this question!