Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:34:10+00:00 2026-06-11T02:34:10+00:00

For my current code, it will download the images first then only display data

  • 0

For my current code, it will download the images first then only display data and cause the device like lagging.

public Custom_ListField(Vector content, boolean islatest) {
    this.content = content;
    this.islatest = islatest;

    newsid = new int[content.size()];
    title = new String[content.size()];
    category = new String[content.size()];
    date = new String[content.size()];
    imagepath = new String[content.size()];
    catsid = new int[content.size()];
    imagebitmap = new Bitmap[content.size()];
    ischeck = new boolean[content.size()];

    for (int i = 0; i < content.size(); i++) {
        newslist = (List_News) content.elementAt(i);
        newsid[i] = newslist.getID();
        title[i] = newslist.getNtitle();
        category[i] = newslist.getNewCatName();
        date[i] = newslist.getNArticalD();
        imagepath[i] = newslist.getImagePath();
        catsid[i] = newslist.getCatID();
        ischeck[i] = false;

        if (!imagepath[i].toString().equals("no picture")) {
            if (Config_GlobalFunction.isConnected())
                imagebitmap[i] = Util_ImageLoader.loadImage(imagepath[i]);
            else
                imagebitmap[i] = localimage;
        }
    }
    initCallbackListening();
}

private void initCallbackListening() {
    callback = new ListCallback();
    this.setCallback(callback);
    this.setRowHeight(-2);
}

private class ListCallback implements ListFieldCallback {
    public ListCallback() {

    }

    public void drawListRow(ListField listField, Graphics graphics,
            final int index, int y, int width) {
        currentPosition = index;

        if (!imagepath[index].toString().equals("no picture")) {
            float ratio = (float) ((float) localimage.getHeight() / (float) imagebitmap[index]
                    .getHeight());
            Bitmap temp = new Bitmap(
                    (int) (imagebitmap[index].getWidth() * ratio),
                    (int) (imagebitmap[index].getHeight() * ratio));
            imagebitmap[index].scaleInto(temp, Bitmap.FILTER_BILINEAR,
                    Bitmap.SCALE_TO_FIT);
            imagebitmap[index] = temp;

            graphics.drawBitmap(
                    Display.getWidth()
                            - localimage.getWidth()
                            - 5
                            + ((localimage.getWidth() - imagebitmap[index]
                                    .getWidth()) / 2),
                    y
                            + (listField.getRowHeight(index) - imagebitmap[index]
                                    .getHeight()) / 2,
                    imagebitmap[index].getWidth(),
                    imagebitmap[index].getHeight(), imagebitmap[index], 0,
                    0);

            graphics.setColor(Color.BLACK);
            text = Config_GlobalFunction
                    .wrap(title[index], Display.getWidth()
                            - imagebitmap[index].getWidth() - 15);

            for (int i = 0; i < text.size(); i++) {
                int liney = y + (i * Font.getDefault().getHeight());
                graphics.drawText(
                        (String) text.elementAt(i),
                        5,
                        liney + 3,
                        DrawStyle.TOP | DrawStyle.LEFT | DrawStyle.ELLIPSIS,
                        Display.getWidth() - imagebitmap[index].getWidth()
                                - 10);
            }
        } else {
            graphics.setColor(Color.BLACK);
            text = Config_GlobalFunction.wrap(title[index],
                    Display.getWidth() - 10);
            for (int i = 0; i < text.size(); i++) {
                int liney = y + (i * Font.getDefault().getHeight());
                graphics.drawText(
                        (String) text.elementAt(i),
                        5,
                        liney + 3,
                        DrawStyle.TOP | DrawStyle.LEFT | DrawStyle.ELLIPSIS,
                        Display.getWidth() - 10);
            }
        }

        if (text.size() == 2) {
            graphics.setColor(Color.GRAY);
            graphics.drawText(date[index], 5, y
                    + Font.getDefault().getHeight() + 3);

            if (islatest) {
                graphics.setColor(Color.RED);
                graphics.drawText(category[index], Font.getDefault()
                        .getAdvance(date[index]) + 15, y
                        + Font.getDefault().getHeight() + 3);
            }
        } else if (text.size() == 3) {
            graphics.setColor(Color.GRAY);
            graphics.drawText(date[index], 5, y
                    + Font.getDefault().getHeight() * 2 + 3);

            if (islatest) {
                graphics.setColor(Color.RED);
                graphics.drawText(category[index], Font.getDefault()
                        .getAdvance(date[index]) + 15, y
                        + Font.getDefault().getHeight() * 2 + 3);
            }
        }

        if (!imagepath[index].toString().equals("no picture"))
            setRowHeight(index, imagebitmap[index].getHeight() + 10);
        else {
            if (text.size() == 2)
                setRowHeight(index, getRowHeight() + 9);
            else if (text.size() == 3) {
                setRowHeight(index, getRowHeight() * 15 / 10 + 9);
            }
        }

        graphics.setColor(Color.WHITE);
        graphics.drawRect(0, y, width, listField.getRowHeight(index));

        ischeck[index] = true;
    }
 }

I want this imagebitmap[i] = Util_ImageLoader.loadImage(imagepath[i]); run after display data so that no need stuck there. However, I tried to put inside drawListRow, it works but very slow because initially display it will run 0-8 times then when i scroll the listfield, it run again. It was download and download again.

Update

public class Util_LazyLoader implements Runnable {
String url = null;
BitmapDowloadListener listener = null;

public Util_LazyLoader(String url, BitmapDowloadListener listener) {
    this.url = url;
    this.listener = listener;
}

public void run() {
    Bitmap bmpImage = getImageFromWeb(url);
    listener.ImageDownloadCompleted(bmpImage);
}

private Bitmap getImageFromWeb(String url) {
    HttpConnection connection = null;
    InputStream inputStream = null;
    EncodedImage bitmap;
    byte[] dataArray = null;

    try {
        connection = (HttpConnection) (new ConnectionFactory())
                .getConnection(url + Database_Webservice.ht_params)
                .getConnection();

        int responseCode = connection.getResponseCode();
        if (responseCode == HttpConnection.HTTP_OK) {
            inputStream = connection.openDataInputStream();
            dataArray = IOUtilities.streamToBytes(inputStream);
        }
    } catch (Exception ex) {
    } finally {
        try {
            inputStream.close();
            connection.close();
        } catch (Exception e) {
        }
    }

    if (dataArray != null) {
        bitmap = EncodedImage.createEncodedImage(dataArray, 0,
                dataArray.length);
        return bitmap.getBitmap();
    } else {
        return null;
    }
}
}

I created a new class but i don’t know how to use it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:34:11+00:00Added an answer on June 11, 2026 at 2:34 am

    you should create method on thread where you are putting the data from Url to vector. this could be in your connection class where you have extend as thread.
    like this>>>>

    getimagemethod(image[i]);
    

    after you declare your method get the image string url to the method. like this>>

    private void getimagemethod(String image2) 
    {
    this.imageforlist = image2;
    

    // you should declare imageforlist string as global string..

    newBitmap1 = Util_ImageLoader.getImageFromUrl(imageforlist);
    

    //newBitmap1 is also global Bitmap..**
    }

    after this put your bitmap which is newBitmap1 to the Vector like this>>

    imagevct.addElement(newBitmap1);
    

    here imagevct is vector which is also global**
    **inorder to create global vector use this….

    private Vector imagevct = new Vector();
    

    now you are ready to draw the bitmap on your list

    for that do it like this…

    public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
    Bitmap imagee = (Bitmap) imagevct.elementAt(index);
    g.drawBitmap(HPADDING, 15 + y, 60, 60, imagee , 0, 0);
    }
    

    Here HPADDING is>>>>
    private static final int HPADDING = Display.getWidth() <= 320 ? 6 : 8;

    this is just tutorial sample step by step..
    if any query then you can post here…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm create a download manager with listview and it will display the current downloaded
I have this following code which will return all the current semesters. How do
The following code downloads a image from Amazon S3 into the device, and then
I have the following code that will download a file asynchronously to my hard-drive,
current code (not working): /^script\s*type=\text\/javascript/i.test(tagName)
current code I've built function to do something over collection of jQuery elements: var
My current code uploads image successfully but still it does not show Toast message
My current code is this $swift = email::connect(); $swift->setSubject('hello') ->setFrom(array('alex@example.com.au' => 'Alex')) ->setTo(array('alex@example.com.au' =>
My current code needs to read foreign characters from the web, currently my solution
Here is the current code in my application: String[] ids = str.split("/"); When profiling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.