Search…
Accordion

Overview

Accordions are used to show and hide text through user interaction.
In Totalcross this component is called AccordionContainer

Source Code

AccordionSample.java
1
import totalcross.sys.Settings;
2
import totalcross.ui.AccordionContainer;
3
import totalcross.ui.MainWindow;
4
import totalcross.ui.MultiEdit;
5
import totalcross.ui.font.Font;
6
import totalcross.ui.gfx.Color;
7
8
public class AccordionSample extends MainWindow {
9
10
public AccordionSample() {
11
setUIStyle(Settings.MATERIAL_UI);
12
Settings.uiAdjustmentsBasedOnFontHeight = true;
13
}
14
15
public void initUI() {
16
int gap = (int) (Settings.screenDensity * 20);
17
18
AccordionContainer.Group gr = new AccordionContainer.Group();
19
AccordionContainer ac[] = new AccordionContainer[5];
20
MultiEdit me[] = new MultiEdit[5];
21
22
for (int i = 0; i < ac.length; i++) {
23
ac[i] = new AccordionContainer(gr);
24
ac[i].setFont(font.asBold());
25
me[i] = new MultiEdit(50, gap / 4);
26
me[i].setText("Type here!");
27
}
28
29
add(ac[0], CENTER, AFTER + gap * 2, SCREENSIZE + 85, PREFERRED);
30
ac[0].setBackForeColors(0xBFDCF7, Color.BLACK);
31
ac[0].add(ac[0].new Caption("...the biggest state?"), LEFT, TOP, FILL, PREFERRED);
32
ac[0].add(me[0], LEFT + gap * 4, AFTER + gap, FILL, FONTSIZE + 600);
33
me[0].transparentBackground = true;
34
me[0].setFont(Font.getFont(false, this.getFont().size));
35
36
for (int i = 1; i < ac.length; i++) {
37
add(ac[i], CENTER, AFTER + gap / 2, SCREENSIZE + 85, PREFERRED);
38
ac[i].setBackForeColors(0xBFDCF7, Color.BLACK);
39
40
switch (i) {
41
case 1:
42
ac[i].add(ac[i].new Caption("...the most famous forest?"), LEFT, TOP, FILL, PREFERRED);
43
break;
44
case 2:
45
ac[i].add(ac[i].new Caption("...the current president?"), LEFT, TOP, FILL, PREFERRED);
46
break;
47
case 3:
48
ac[i].add(ac[i].new Caption("...the most famous river?"), LEFT, TOP, FILL, PREFERRED);
49
break;
50
case 4:
51
ac[i].add(ac[i].new Caption("...the most famous statue?"), LEFT, TOP, FILL, PREFERRED);
52
break;
53
}
54
ac[i].add(me[i], LEFT + gap * 4, AFTER + gap, FILL, FONTSIZE + 600);
55
me[i].setFont(Font.getFont(false, ac[i].getFont().size));
56
me[i].transparentBackground = true;
57
}
58
}
59
60
public int getScreenWidth() {
61
return Settings.screenWidth;
62
}
63
}
Copied!

Attributes

Type
Name
Description
int
minH
Minimum height of the closed accordion

Methods

Type
Name
Description
Constructor
AccordionContainer( )
Creates a empty accordion
Constructor
AccordionContainer(AccordionContainer.Group g)
Creates a list of accordions from the accordion group.
void
collapse( )
Closes the accordion
void
collapse(boolean showAnimation)
Closes the accordion with animation(depending on the parameter)
void
expand( )
Open the accordion
void
expand(boolean showAnimation)
Open the accordion with animation(depending on the parameter)
int
getPreferredHeight( )
Returns the accordion´s minimum height
boolean
isExpanded( )
Retorna true if the accordion is open
void
onAnimationFinished(ControlAnimation anim)
This method is called after the animation is finished
void
setPos(int x, int y)
Set the accordion´s x and y position

References

Last modified 2yr ago