LWUIT List的工作速度非常慢

时间:2012-10-25 17:38:02

标签: list checkbox lwuit renderer

我遇到了LWUIT中众所周知的问题。带有复选框渲染器的列表组件滚动速度非常慢。如果要在模拟器上测试我的应用程序,它运行得非常顺利(尽管如此,我认为在滚动操作期间CPU利用率会高达60%),但如果要在手机上运行它,则需要几秒钟的焦点移动。

有一个渲染器代码:

public class CheckBoxMultiselectRenderer extends CheckBox implements ListCellRenderer {

public CheckBoxMultiselectRenderer() {
    super("");
}

//override
public void repaint() {
}

public Component getListCellRendererComponent(List list, Object value, 
 int index,boolean isSelected) {
    Location loc = (Location)value;
    setText(loc.getLocationName());
    setFocus(isSelected);
    setSelected(loc.isSelected());

    return this;
}

public Component getListFocusComponent(List list) {
    setText("");
    setFocus(true);
    getStyle().setBgTransparency(Consts.BG_TRANSPARENCY);
    return this;
}
}

这是包含列表的表单代码:

protected void createMarkup() {
    Form form = getForm();
    form.setLayout(new BorderLayout());
    form.setScrollable(false);

    Label title = new Label("Choose location zone:");
    title.getStyle().setMargin(5, 5, 0, 0);
    title.getStyle().setBgTransparency(Consts.BG_TRANSPARENCY);
    title.setAlignment(Component.CENTER);

    form.addComponent(BorderLayout.NORTH, title);

    list = new List(StateKeeper.getLocationsAsList());
    list.setFixedSelection(List.FIXED_NONE_CYCLIC);
//        list.setSmoothScrolling(true);
    list.getStyle().setBgTransparency(0);
    list.setListCellRenderer(new CheckBoxMultiselectRenderer());
    list.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
//                List l = (List)ae.getSource();
//                l.requestFocus();
//                l.setHandlesInput(true);
            Location selItem = (Location)list.getSelectedItem();
            selItem.setSelected(!selItem.isSelected());
        }
    });

    form.addComponent(BorderLayout.CENTER, list);
}

我会非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

我们必须非常谨慎地建立lwuit List。如果我们犯了错误,他们可能会比预期更糟糕。我建议你看看这个

LWUIT Blog ListRender

您还可以重写您的绘画方法。你的名单速度会提高。