views:

505

answers:

1

Trying to create a custom cyclical horizontal manager which will work as follows. It will control several field buttons where the buttons will always be positioned so that the focused button will be in the middle of the screen. As it is a cyclical manager once the focus moves to the right or left button, it will move to the center of the screen and all the buttons will move accordingly (and the last button will become the first to give it an cyclic and endless list feeling)

Any idea how to address this?

I tried doing this by implementing a custom manager which aligns the buttons according to the required layout. Each time moveFocus() is called I remove all fields (deleteAll() ) and add them again in the right order. Unfortunately this does not work.

A: 

Using HorizontalButtonFieldSet class from KB How to - Implement advanced buttons, fields, and managers:

class CentricHManager extends HorizontalButtonFieldSet {
    int focusedFieldIndex = 0;

    public void focusChangeNotify(int arg0) {
        super.focusChangeNotify(arg0);
        int focusedFieldIndexNew = getFieldWithFocusIndex();
        if (focusedFieldIndexNew != focusedFieldIndex) {
            if (focusedFieldIndexNew - focusedFieldIndex > 0)
                switchField(0, getFieldCount() - 1);
            else
                switchField(getFieldCount() - 1, 0);
        }
    }

    private void switchField(int prevIndex, int newIndex) {
        Field field = getField(prevIndex);
        delete(field);
        insert(field, newIndex);
    }

    public void add(Field field) {
        super.add(field);
        focusedFieldIndex = getFieldCount() / 2;
        setFieldWithFocus(getField(focusedFieldIndex));
    }
}
Max Gontar