开发者

Blackberry bitmapfield focus unfocus issue

开发者 https://www.devze.com 2023-03-25 13:57 出处:网络
I am adding three bitmap in my screen.The image needs to change with focus and unfocus.Now if i declare the bitmaps inside my customised method,than wheni scroll from one image to another,it gives nul

I am adding three bitmap in my screen.The image needs to change with focus and unfocus.Now if i declare the bitmaps inside my customised method,than wheni scroll from one image to another,it gives null pointer exception.But when i declare the bitmaps outside the method,i dont get any exception,but only the last focused image gets focused everywhere,but it should be like that for three images three seperate focused images are there.Below is my code.Please help.

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 v开发者_如何转开发oid 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();
            }


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

精彩评论

暂无评论...
验证码 换一张
取 消