1
votes

How to collapse a codename one accordion component programmatically?

In my App, I have an accordion that expands a body container with some radio buttons. I want to collapse (Close) the body automatically when a radio button is selected.

Adding more details about the problem:

My intention is create a component that has same behavior of a ComboBox, but using Accodion component as base class. I wrote a minimal use case that reproduce the problem and you can get its source file here MyApplication.java.
This code implements Steve Hanna answer.I suppose. And it didn't work for me.

Running this code is simple. Just create a CodeName One project and replace the MyApplication.java file generated by CodeName One Wizard and run the project (I use Netbeans IDE). I put inside Radio Button action the command to collapse the component as you can see at lines 271 til 280. But it didn't work.

1

1 Answers

1
votes

In the radio button's action listener, check if it's not selected and then call collapse(bodyContainer) on the accordion.

EDIT: There was a bug in Accordion that caused collapse() to work incorrectly. This has now been fixed, and will be available in the next plugin update.

See this sample to see correct usage.

Note that after calling collapse(component), you should call the Accordion's animateLayout() method so that the change is shown.