Search…
Spin List

Overview

Spin list is a control that has two arrows (up and down) to navigate between the information contained in the control, it is possible to navigate by clicking or holding the arrows or navigating the keyboard arrows.

Source Code

SpinList Sample
1
import totalcross.sys.InvalidNumberException;
2
import totalcross.sys.Settings;
3
import totalcross.ui.Container;
4
import totalcross.ui.MainWindow;
5
import totalcross.ui.SpinList;
6
import totalcross.ui.gfx.Color;
7
import totalcross.util.UnitsConverter;
8
9
public class SpinListSample extends MainWindow {
10
11
int gap = UnitsConverter.toPixels(DP + 8);
12
13
public SpinListSample(){
14
setUIStyle(Settings.MATERIAL_UI);
15
}
16
17
@Override
18
public void initUI() {
19
try {
20
SpinList sl = new SpinList(new String[]{"Blue", "Orange","Yelow", "Red"});
21
sl.allowsNoneSelected = true;
22
add(sl, LEFT + gap, TOP + gap, FILL, PREFERRED);
23
24
Container paintContainer = new Container();
25
add(paintContainer, SAME, AFTER + gap, FILL - gap, FILL - gap);
26
27
28
sl.addPressListener(e -> {
29
switch (sl.getSelectedIndex()){
30
case -1:
31
paintContainer.setBackColor(Color.WHITE);
32
break;
33
case 0:
34
paintContainer.setBackColor(Color.BLUE);
35
break;
36
case 1:
37
paintContainer.setBackColor(Color.ORANGE);
38
break;
39
case 2:
40
paintContainer.setBackColor(Color.YELLOW);
41
break;
42
case 3:
43
paintContainer.setBackColor(Color.RED);
44
break;
45
}
46
});
47
48
} catch (InvalidNumberException e) {
49
e.printStackTrace();
50
}
51
}
52
}
Copied!

Attributes

Type
Name
Description
boolean
isVertical
Set to true if there are only numbers in the SpinList and you want to open a NumericBox
boolean
useNumericBox
Set to true if there are only numbers in the SpinList and you want to open a NumericBox
boolean
useCalculatorBox
Set to false to disallow the wrap around that happens when the user is at the first or last items.
boolean
wrapAround
By default, equals the choices' length. You can define its length and then create a single array shared by a set of SpinLists with different lengths on each SpinList
boolean
allowsNoneSelected
Allows -1 as selected index

Methods

Type
Name
Description
Constructor
SpinList(String[] choices)
Constructs a vertical SpinList with the given choices, selecting index 0 by default.
Constructor
SpinList(String[] choices, boolean isVertical)
Constructs a SpinList with the given choices, selecting index 0 by default and can be vertical or not.
int
getPreferredWidth()
Return the width.
int
getPreferredHeight()
Return the Height.
void
setChoices(String[] choices)
Sets the choices to the given ones
void
replaceChoices(String[] choices)
Just replaces the choices array.
int
getSelectedIndex()
Returns the selected index.
String
getSelectedItem()
Returns the selected item.

References