BlackBerry - Custom centered cyclic HorizontalFieldManager

喜欢而已 提交于 2019-11-29 16:54:00

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));
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!