Blackberry Invalidate picturescrollfield

Blackberry Invalidate picturescrollfield,blackberry,Blackberry,I am loading images in PictureScrollField from the server and want that until images are loaded from server, the PictureScrollField shows a blank image and when the image loads in image array, it repaints (redraw) the PictureScrollField like a ListField. I read from BlackBerry documentation that every field can be invalidated (that is, we can repaint it) but when I use the PictureScrollField.invalidate() method in my program, I get an error : The method invalidate from the type Field is not

I am loading images in

PictureScrollField
from the server and want that until images are loaded from server, the
PictureScrollField
shows a blank image and when the image loads in image array, it repaints (redraw) the
PictureScrollField
like a
ListField
.

I read from BlackBerry documentation that every field can be invalidated (that is, we can repaint it) but when I use the

PictureScrollField.invalidate()
method in my program, I get an error :

The method invalidate from the type Field is not visible

The program I use is listed below

public final class GetMoreImage extends MainScreen {
    public static PictureScrollField psf;
    int size;
    int length;
    String text=null;
    EncodedImage[] encodedImage;
    VerticalFieldManager vmanger;
    private LoadImages loadImages;

    public GetMoreImage(int index) {
        super(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR);
        this.size=index;
        try {
            length=ListHome.object[size].getJSONArray("UrlArray").length();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        ScrollEntry[] entries = new ScrollEntry[length];
        for (int i = 0; i < length; i++) {
            if(encodedImage != null && encodedImage.length > i && encodedImage[i] != null) {
                EncodedImage encodedImg =ListHome.sizeImage(JPEGEncodedImage.encode(Bitmap.getBitmapResource("icon.png"),80),640,380);
                Bitmap bmp=encodedImg.getBitmap();
                entries[i] = new ScrollEntry(bmp, "hello", "");
            }
            else {
                try {
                    text=ListHome.object[size].getJSONArray("UrlArray").getString(i).toString();
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                EncodedImage encodedImg =ListHome.sizeImage(JPEGEncodedImage.encode(connectServerForImage(text),80),640,380);
                Bitmap bmp=encodedImg.getBitmap();
                entries[i] = new ScrollEntry(bmp, "hello", "");
            }
        }

        psf = new PictureScrollField();
        psf.setData(entries, 0);
        psf.setHighlightStyle(HighlightStyle.ILLUMINATE_WITH_SHRINK_LENS);
        add(psf);
        loadImages = new LoadImages(80, 80);
        loadImages.start();
    }

    private class LoadImages extends Thread {
        int widthL;
        int heightL;

        LoadImages(int width, int height) {
            this.widthL = width;
            this.heightL = height;
        }

        public void run() {
            encodedImage=new EncodedImage[length];
            if (ListHome.object[size] != null) {
                for (int i = 0; i < length; i++) {
                    try {
                        String text=ListHome.object[size].getJSONArray("UrlArray").getString(i).toString();
                        EncodedImage encodedImg = JPEGEncodedImage.encode(connectServerForImage(text), 80);//Get Image from Server
                        encodedImage[i] = ListHome.sizeImage(encodedImg, Display.getWidth(), Display.getHeight()-100);
                        psf.invalidate();//This Line generate error
                    } catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            } else {
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        Dialog.alert("No Data Found");
                    }
                });
            }
        }
    }
}

Any help will be appreciated.

Thanks


#1

The reason you get a compile error on this line:

 psf.invalidate();//This Line generate error

is because the PictureScrollField#invalidate() method is protected, not public. So, code not in PictureScrollField or a class that extends PictureScrollField cannot use it directly.

However, you don't need to use invalidate(). invalidate() is a low-level method that instructs a field to repaint. However, PictureScrollField has a higher-level method that is designed to allow you to change images, and have the field (re)draw them: PictureScrollField#setData().

Because that method is changing the user interface (UI), it should be run on the UI/main thread. This will not automatically happen if you make the call inside the run() method you are using to download the images. So, you'll need something like this inside your LoadImages class:

public void run() {
    encodedImage=new EncodedImage[length];
    if (ListHome.object[size] != null) {
        for (int i = 0; i < length; i++) {              
            try {
                String text=ListHome.object[size].getJSONArray("UrlArray").getString(i).toString();
                EncodedImage encodedImg = JPEGEncodedImage.encode(connectServerForImage(text), 80);//Get Image from Server                          
                encodedImage[i] = ListHome.sizeImage(encodedImg, Display.getWidth(), Display.getHeight()-100);

                //psf.invalidate();//This Line generate error
                entries[i] = new ScrollEntry(encodedImage[i].getBitmap(), "label", "callout");
                // we must update the scroll entries on the UI/main thread:
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                   // setting the field to index 'i' will scroll to the image
                   //   that was just downloaded
                   psf.setData(entries, i);
                });                        
            } catch (Exception e) 
            {
                e.printStackTrace();
            }
        }
    } 

In order to make this work, you must change the local entries variable to a member variable in your GetMoreImage class:

 public final class GetMoreImage extends MainScreen {
     public static PictureScrollField psf;
     private ScrollEntry[] entries;

but, you can still instantiate it (entries = new ScrollEntry[length];) in your screen's constructor, or whenever you know the correct length.


#2

The reason you get a compile error on this line:

 psf.invalidate();//This Line generate error

is because the PictureScrollField#invalidate() method is protected, not public. So, code not in PictureScrollField or a class that extends PictureScrollField cannot use it directly.

However, you don't need to use invalidate(). invalidate() is a low-level method that instructs a field to repaint. However, PictureScrollField has a higher-level method that is designed to allow you to change images, and have the field (re)draw them: PictureScrollField#setData().

Because that method is changing the user interface (UI), it should be run on the UI/main thread. This will not automatically happen if you make the call inside the run() method you are using to download the images. So, you'll need something like this inside your LoadImages class:

public void run() {
    encodedImage=new EncodedImage[length];
    if (ListHome.object[size] != null) {
        for (int i = 0; i < length; i++) {              
            try {
                String text=ListHome.object[size].getJSONArray("UrlArray").getString(i).toString();
                EncodedImage encodedImg = JPEGEncodedImage.encode(connectServerForImage(text), 80);//Get Image from Server                          
                encodedImage[i] = ListHome.sizeImage(encodedImg, Display.getWidth(), Display.getHeight()-100);

                //psf.invalidate();//This Line generate error
                entries[i] = new ScrollEntry(encodedImage[i].getBitmap(), "label", "callout");
                // we must update the scroll entries on the UI/main thread:
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                   // setting the field to index 'i' will scroll to the image
                   //   that was just downloaded
                   psf.setData(entries, i);
                });                        
            } catch (Exception e) 
            {
                e.printStackTrace();
            }
        }
    } 

In order to make this work, you must change the local entries variable to a member variable in your GetMoreImage class:

 public final class GetMoreImage extends MainScreen {
     public static PictureScrollField psf;
     private ScrollEntry[] entries;

but, you can still instantiate it (entries = new ScrollEntry[length];) in your screen's constructor, or whenever you know the correct length.


#3

Really you are a genius person .Today I implemented what I want.I appreciate for this.Further It is an request to you to Please See this link and suggest what to do next stackoverflow.com/questions/19636394/…

#4

:Still waiting for your respons for this Question : stackoverflow.com/questions/19636394/… for Question

#5

Really you are a genius person .Today I implemented what I want.I appreciate for this.Further It is an request to you to Please See this link and suggest what to do next stackoverflow.com/questions/19636394/…

#6

:Still waiting for your respons for this Question : stackoverflow.com/questions/19636394/… for Question