黑莓BitmapField焦点 - 非焦点概率

时间:2012-03-23 13:16:07

标签: blackberry bitmap onfocus

我想在BitmapField的焦点上的特定标签中设置文字,并重置非焦点上的文字。我使用以下代码:

final BitmapField tab1 = new BitmapField(Bitmap.getBitmapResource("img/icon1.png"), FIELD_BOTTOM | BitmapField.FOCUSABLE) {
    protected void drawFocus(Graphics graphics, boolean on) {
        // the simplies way to draw a rectangle and this will be the
        // focus

    }

    protected boolean navigationClick(int status, int time) {
        // write here your code what you want to run the user clicks to
        // the bitmap
        // try something like this
        Dialog.alert("Code for tab1");
        return true;
    }

    public void setFocus(){
        super.setFocus();
        selectedLabel.setText("tab1");      
    }

    public void onUnfocus(){
        super.onUnfocus();
        selectedLabel.setText("");  
    }

};

但焦点正在改变,但标签根本没有设置。我的代码中的问题在哪里?

3 个答案:

答案 0 :(得分:2)

覆盖onFocus(int direction)而不是setFocus()

答案 1 :(得分:1)

protected void onFocus(int direction) {
    super.onFocus(direction);
    selectedLabel.setText("tab1");
}

protected void onUnfocus() {
    super.onUnfocus();
    selectedLabel.setText("");
}

答案 2 :(得分:0)

使用onfocus()& onUnfocus()方法,并将这两种方法中的LabelField替换为Invalidate()选项。