blackberryblackberry-editfield

Blackberry custom EditField - handle focus


Something is driving me crazy on BlackBerry dev. I have a custom EditField. Here is the code:

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

The thing is that it cannot get the focus. Actually it does call isFocusable etc. but the cursor doesn't show and I cannot write anything. I am surely missing something as I'm new to BlackBerry dev, but what ?

Thanks a lot


Solution

  • I've actually found the answer. I totally forgot to call the super.layout method. So the layout method should be:

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