2012-03-23 89 views
0

我想在BitmapField的焦點上的特定標籤中設置一個文本,並重置未聚焦的文本。我正在使用以下代碼:黑莓BitmapField focus-unfocus prob

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

}; 

但是重點正在改變,但標籤根本沒有設置。我的代碼中的問題在哪裏?

回答

2

覆蓋的onFocus(int direction)代替setFocus()

0

使用onfocus() & onUnfocus()方法和方法都與Invalidate()選項取代你LabelField

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

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