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
import totalcross.sys.InvalidNumberException;
import totalcross.sys.Settings;
import totalcross.ui.Container;
import totalcross.ui.MainWindow;
import totalcross.ui.SpinList;
import totalcross.ui.gfx.Color;
import totalcross.util.UnitsConverter;

public class SpinListSample extends MainWindow {

    int gap = UnitsConverter.toPixels(DP + 8);

    public SpinListSample(){
        setUIStyle(Settings.MATERIAL_UI);
    }

    @Override
    public void initUI() {
        try {
            SpinList sl = new SpinList(new String[]{"Blue", "Orange","Yelow", "Red"});
            sl.allowsNoneSelected = true;
            add(sl, LEFT + gap, TOP + gap, FILL, PREFERRED);

            Container paintContainer = new Container();
            add(paintContainer, SAME, AFTER + gap, FILL - gap, FILL - gap);


            sl.addPressListener(e -> {
                switch (sl.getSelectedIndex()){
                    case -1:
                        paintContainer.setBackColor(Color.WHITE);
                        break;
                    case 0:
                        paintContainer.setBackColor(Color.BLUE);
                        break;
                    case 1:
                        paintContainer.setBackColor(Color.ORANGE);
                        break;
                    case 2:
                        paintContainer.setBackColor(Color.YELLOW);
                        break;
                    case 3:
                        paintContainer.setBackColor(Color.RED);
                        break;
                }
            });

        } catch (InvalidNumberException e) {
            e.printStackTrace();
        }
    }
}

Attributes

Methods

References

Last updated