黑莓自定义EditField - 处理焦点

时间:2011-04-28 15:18:55

标签: blackberry blackberry-editfield

有些东西让我在BlackBerry dev上疯狂。我有自定义EditField。这是代码:

private EditField m_Txt=new EditField(EditField.FOCUSABLE |
                                        EditField.FILTER_DEFAULT) {
    protected void layout(int width, int height)
    {
        setExtent(Display.getWidth(), m_TxtHeight);
    }
    public boolean isFocusable()
    {
        return true;
    }

    protected void onFocus(int direction)
    {
        super.onFocus(direction);
        invalidate();
    }

    protected void onUnfocus() {
        super.onUnfocus();
        invalidate();
    }
};

事情是它无法获得焦点。实际上它确实调用isFocusable等,但光标没有显示,我不能写任何东西。我肯定遗失了一些东西,因为我是BlackBerry dev的新手,但是什么?

非常感谢

2 个答案:

答案 0 :(得分:1)

您正在测试哪种操作系统?如果是最近的OS6版本I've found in those versions,则在启用选择模式之前,您不会在文本编辑字段中获得光标。

答案 1 :(得分:1)

我实际上找到了答案。我完全忘了调用super.layout方法。所以布局方法应该是:

protected void layout(int width, int height)
{
    super.layout(Display.getWidth(), m_TxtHeight);
    setExtent(Display.getWidth(), m_TxtHeight);
}
相关问题