0

我正在使用以下代码进行列表。我已经用于RichTextField列表项目。

public class ListScreen extends MainScreen {

    private UiApplication application;
    private VerticalFieldManager listManager;

    /**
     * 
     */
    public ListScreen() {
        super(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL | USE_ALL_HEIGHT
                | USE_ALL_WIDTH);
        // TODO Auto-generated constructor stub

        this.application = UiApplication.getUiApplication();

        LabelField screenHeading = new LabelField("Category",
                FIELD_HCENTER) {
            protected void paint(net.rim.device.api.ui.Graphics g) {
                g.setColor(Color.WHITE);
                super.paint(g);
            }
        };
        final VerticalFieldManager labelMngr = new VerticalFieldManager(USE_ALL_WIDTH);
        labelMngr.setBackground(BackgroundFactory
                .createBitmapBackground(LangValue.labelbg));
        labelMngr.add(screenHeading);
        labelMngr.setPadding(5, 0, 5, 0);
        add(labelMngr);

        try {

            listManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL
                    | Manager.VERTICAL_SCROLLBAR) {

                protected void sublayout(int maxWidth, int maxHeight) {
                    int width = Display.getWidth();
                    int height = Display.getHeight()
                            - labelMngr.getHeight();

                    super.sublayout(width, height);
                    setExtent(width, height);
                }
            };

            listManager.setPadding(5, 0, 5, 0);

            int i=0;
            RichTextField rtf;
            Background background = BackgroundFactory
                    .createSolidBackground(Color.WHITE);
            Border border = BorderFactory.createSimpleBorder(new XYEdges(0, 0,
                    2, 0));

            CategoryHelper categoryHelper = new CategoryHelper();
            final String[][] cetegoryList = categoryHelper.getCategoryList();
            for(; i < cetegoryList.length ; i++) {

                rtf = new RichTextField(cetegoryList[i][1], Field.FOCUSABLE) {
                    protected boolean navigationClick(int status, int time) {

                        fieldChangeNotify(1);

                        return true;
                    }

                    protected boolean touchEvent(
                            net.rim.device.api.ui.TouchEvent message) {
                        if (TouchEvent.CLICK == message.getEvent()) {
                            FieldChangeListener listener = getChangeListener();
                            if (null != listener)
                                listener.fieldChanged(this, 1);
                        }
                        return super.touchEvent(message);
                    }

                };
                rtf.setBackground(Field.VISUAL_STATE_NORMAL, background);
                rtf.setBorder(border);
                rtf.setPadding(1, 2, 1, 3);
                rtf.setCookie(new Category(Integer.parseInt(cetegoryList[i][0]),cetegoryList[i][1]));
                rtf.setChangeListener(new FieldChangeListener() {
                    public void fieldChanged(Field field, int context) {
                        // Dialog.alert("play the video");
                        // System.out.print("play the video");
                        // code for play video
                    }
                });
                listManager.add(rtf);
            }
            if (i == 0) {
                listManager.add(new RichTextField("No word found."));
            }

            add(listManager);

        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }    

}

它适用于模拟器。我可以滚动列表,并可以通过滚动将焦点设置在任何项目上,并且焦点项目获得蓝色标记。但是当我在测试 BB 设备时,该项目已聚焦,但聚焦状态不可见且颜色不变,这意味着用户无法识别哪个是聚焦的。我的代码有什么问题?

4

1 回答 1

2

I have added the following code in anonymous class of RichTextField.

protected void onFocus(int direction){
        super.onFocus(direction);
        this.setBackground(BackgroundFactory.createSolidBackground(0x001865D6));
        invalidate();
    }

    protected void onUnfocus(){
        super.onUnfocus();
        this.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
        invalidate();
    }
于 2012-04-06T13:46:47.080 回答