BlackBerry - Custom centered cyclic HorizontalFieldManager

后端 未结 1 1185
半阙折子戏
半阙折子戏 2020-12-22 02:43

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 t

相关标签:
1条回答
  • 2020-12-22 03:42

    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));
        }
    }
    
    0 讨论(0)
提交回复
热议问题