2010-12-02 76 views
0

我有一個類似於下面的代碼,在mapfields這個mIcon上多次繪製。 如何將點擊偵聽器添加到此位圖?我使用的BB 5.0BlackBerry Bitmap listener

public Bitmap mIcon; 
mIcon = Bitmap.getBitmapResource("pcture1.png"); 

protected void paint(Graphics g) { 


super.paint(g); 
     mDest = new XYRect(....); 
     g.drawBitmap(mDest, mIcon, 0, 0); 
} 

回答

2

覆蓋BitmapField和修改isFocusable(),navigationClick(),keyChar(),和trackwheelClick()方法。

public class ImageButtonField extends BitmapField 
{ 

    public ImageButtonField(Bitmap image) 
    { 
     super(image); 
    } 

    public boolean isFocusable() 
    { 
     return true; 
    } 

    protected boolean navigationClick(int status, int time) 
    { 
    fieldChangeNotify(0); 
    return true; 
    } 

    protected boolean trackwheelClick(int status, int time) 
    { 
    fieldChangeNotify(0); 
    return true; 
    } 

    protected boolean keyChar(char character, int status, int time) 
    { 
     if(Characters.ENTER == character || Characters.SPACE == character) 
     { 
     fieldChangeNotify(0); 
     return true; 
     } 
     return super.keyChar(character, status, time); 
    } 

} 
+0

您好,感謝您的回答。我如何將它添加到MapField?應該根據與屏幕相關的地圖中心動態添加圖標嗎? – user528097 2010-12-03 06:34:12