2011-06-06 31 views
3

我安排了7個bimapfield水平如果我點擊它想要推另一個屏幕的位圖字段這是我的代碼,但我沒有得到另一個屏幕可以任何人幫助我什麼是錯的此代碼BitmapField點擊不適用於黑莓應用程序

BitmapField bitmap1 = new BitmapField(
    Bitmap.getBitmapResource("profile_n.png"),FOCUSABLE | DrawStyle.HCENTER) 
{ 
    protected void onFocus(int direction) 
    { 
     rollno=1; 
     this.getScreen().invalidate(); 
    } 
    protected void onUnfocus() 
    { 

    } 
    protected boolean navigationClick(int status, int time){ 
      UiApplication.getUiApplication().popScreen(getScreen()); 
      UiApplication.getUiApplication().pushScreen(new AccMainScreen()); 
     return true; 
    } 
}; 

回答

3

您可以使用一個自定義字段來保存圖像,其行爲類似於按鈕而不是位圖字段。 下面是代碼,我建議:

import net.rim.device.api.system.Bitmap; 
import net.rim.device.api.ui.Field; 
import net.rim.device.api.ui.Graphics; 
public class CustomButton extends Field{ 

    protected Bitmap icon; 
    protected int fieldWidth; 
    protected int fieldHeight; 

    public CustomButton (String iconSource,long style) { 
     super(style); 
     icon = Bitmap.getBitmapResource(iconSource); 
     fieldHeight = icon.getHeight(); 
     fieldWidth = icon.getWidth(); 
    } 

    public int getPreferredWidth() { 
     return fieldWidth; 
    } 

    public int getPreferredHeight() { 
     return fieldHeight; 
    } 
    protected void layout(int arg0, int arg1) { 
     setExtent(getPreferredWidth(), getPreferredHeight()); 
    } 
    protected void drawFocus(Graphics graphics, boolean on){ } 

    protected void paint(Graphics graphics) { 
     graphics.fillRect(0, 0, fieldWidth, fieldHeight); 
     graphics.drawBitmap(0,0, fieldWidth, fieldHeight, icon, 0, 0); 
    } 
    protected boolean navigationClick(int status, int time) { 
     fieldChangeNotify(0); 
     return true; 
    } 
} 

您可以使用該按鈕就像一個默認的按鈕,並通過使用setChangeListener功能改變它的聽衆。

CustomButton aButton = new CustomButton ("graphics/someIcon.png"); 
aButton.setChangeListener(new FieldChangeListener() { 
    public void fieldChanged(Field field, int context) { 
     UiApplication.getUiApplication().popScreen(getScreen()); 
     UiApplication.getUiApplication().pushScreen(new AccMainScreen()); 
    } 
}); 
+0

謝謝你我輸出了 – keerthika 2011-06-07 09:04:29