0

I am using following code for a listing. I have used RichTextField for items of list.

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();
        }
    }    

}

It is working fine for simulator. I can scroll the list and can set the focus on any item by scrolling and focused item get blue mark. But when I am testing BB device, the item is focused, but the focused state is not visible and unchanged in color which means the user cannot identify which one is focused. What is problem in my code?

1
  • Might be a problem with OS version Apr 5, 2012 at 4:52

1 Answer 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();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.