黑莓bitmapfield焦点焦点问题

时间:2011-08-01 11:11:12

标签: blackberry java-me

我在屏幕上添加了三个位图。图像需要随着焦点和非焦点而改变。现在,如果我在自定义方法中声明位图,那么当我从一个图像滚动到另一个图像时,它会给出空指针异常。但是当我声明方法之外的位图,我没有任何异常,但只有最后一个聚焦的图像到处聚焦,但它应该像三个图像那样三个单独的聚焦图像.Below是我的代码。请帮助。

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

1 个答案:

答案 0 :(得分:1)

BitmapField chaneBitmap(String image1,String image2){
    final Bitmap  original= Bitmap.getBitmapResource(image1);
    final Bitmap change = Bitmap.getBitmapResource(image2);
    BitmapField _hold_bitmap=new BitmapField(original,BitmapField.FOCUSABLE){    
        protected void drawFocus(Graphics graphics, boolean on){} 
            public void onFocus(int direction){
                    invalidate();
                    setBitmap(change);
             }

             public void onUnfocus(){
                     super.onUnfocus();
                     setBitmap(original);
             }
        }
}