0
我在我的屏幕添加三個位圖。圖像需要改變與焦點和unfocus.Now如果我在我的自定義方法內聲明位圖,比wheni從一個圖像滾動到另一個,它會給null指針異常。但是當我在方法外部聲明位圖時,我沒有得到任何異常,但只有最後一個聚焦圖像集中到處,但它應該是像三個圖像三個單獨聚焦的圖像在那裏。下面是我的代碼。請幫忙。黑莓bitmapfield焦點unfocus問題
private BitmapField getBitmapField(final Item item, final int cellWid, final int cellHgt, final long style) {
final Bitmap bitmap = Bitmap.getBitmapResource(item.imgUrl);
final Bitmap bitmapfoc = Bitmap.getBitmapResource(item.imgUrlimp);
BitmapField bitmapField = new BitmapField(bitmap, style) {
boolean _inFocus = false;
protected void onFocus(int direction) {
_inFocus = true;
selectedIndex = flowFieldManager.getFieldWithFocusIndex();
System.out.println("Selected Index :"+selectedIndex);
if(TextControl.labelField != null)
TextControl.labelField.setText(item.title);
super.onFocus(direction);
//this.invalidate();
}
protected void onUnfocus() {
_inFocus = false;
super.onUnfocus();
//this.invalidate();
}
public void paint(Graphics graphics) {
System.out.println("====barView=== :"+barview);
graphics.drawBitmap(0, 0, bitmap.getWidth(),bitmap.getHeight(), bitmap, 0, 0); //draw bachground image bitmap
invalidate();
//super.paint(graphics);
}
protected void drawFocus(Graphics g, boolean arg1) {
g.drawBitmap(0,0, bitmapfoc.getWidth(), bitmapfoc.getHeight(), bitmapfoc, 0, 0); //draw bachground image bitmap
invalidate();
}
不相關的問題,但你不應該叫'無效()'從畫法的內部自'無效()'表示它需要重新繪製。你能否給我們提供任何有用的信息,比如NPE在哪裏被拋出? – jprofitt