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 6833001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:55:36+00:00 2026-05-26T22:55:36+00:00

I am trying to create a custom List Adapter which has an Image for

  • 0

I am trying to create a custom List Adapter which has an Image for every item it needs to download from the internet. When I first enter the Activity – the app freezes for a while till the images are downloaded and then the Activity List is loaded.

As I can make out the images are being downloaded before the activity loads. How can I download the images after the activity has loaded. I think I need to use Async Task. But since I am loading the images in the Custom Array Adapter not sure how to do it.

This is my Custom Adapter’s getView():

public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if (v == null) {
            LayoutInflater vi;
            vi = LayoutInflater.from(getContext());
            v = vi.inflate(R.layout.list_item_default, null);
        }

        Item p = items.get(position);

        if (p != null) {

            TextView list_title = (TextView) v.findViewById(R.id.list_title);
            TextView list_description = (TextView) v
                    .findViewById(R.id.list_description);
            TextView list_timestamp = (TextView) v
                    .findViewById(R.id.list_timestamp);
            ImageView list_image = (ImageView) v.findViewById(R.id.list_image);

            if (list_title != null) {
                list_title.setText(p.getItemTitle());
            }

            if (list_description != null) {
                list_description.setText(p.getItemDescription());
            }

            if (list_timestamp != null) {
                list_timestamp.setText(p.getItemTimestamp());
            }

            if (list_image != null) {
                Log.d("bMobile", "inside getView() image");
                try {
                    URL imageURL = new URL(p.getItemImage());
                    HttpURLConnection con = (HttpURLConnection) imageURL
                            .openConnection();
                    InputStream inputStrem = con.getInputStream();
                    Bitmap image = BitmapFactory.decodeStream(inputStrem);
                    if (null != image)
                        list_image.setImageBitmap(image);
                    else
                        Log.d("bMobile", "Bitmap is Null");
                } catch (Exception e) {
                }
            }
        }

        return v;
    }

AsyncTask:

public class DownloadImagesTask extends AsyncTask<ImageView, Void, Bitmap> {

    ImageView imageView = null;

    @Override
    protected Bitmap doInBackground(ImageView... imageViews) {
        this.imageView = imageViews[0];
        return download_Image((String)imageView.getTag());
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }

}
    private Bitmap download_Image(String url) {

        Bitmap bmp =null;
        try{
            URL ulrn = new URL(url);
            HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
            InputStream is = con.getInputStream();
            bmp = BitmapFactory.decodeStream(is);
            if (null != bmp)
                return bmp;

            }catch(Exception e){}
        return bmp;
    }
  • 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-05-26T22:55:37+00:00Added an answer on May 26, 2026 at 10:55 pm

    “the app freezes” – This is because you are downloading the images on the event thread or UI Thread. You should never do that. All blocking operations,long running operations, network operations, should be run on a separate thread. Yes you can use asynctask to do the image loading which should fix the issue.

    Two options you can do to solve the issue is

    1. Use WebImageView from droid fu library at http://brainflush.wordpress.com/2009/11/23/droid-fu-part-2-webimageview-and-webgalleryadapter/
      WebImageView uses caching as well so you dont need to download images again which you have already downloaded. Downloading images are expensive and consume data.
      I used WebImageView and was able to load images in list. It took me just about 20 mins to get it all working, so you know its easy integrating it.

    2. Second option is to use async task . Please check Android : Loading an image from the Web with Asynctask . There are lot more info in stackoverflow regarding how to do this.

    Any time your UI hangs, you should have a creepy feeling, that you are doing something on the UI thread.

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

Sidebar

Related Questions

I am trying to create a custom context processor which will render a list
I'm trying to create a custom attribute for each list item in a databound
I'm trying to create a custom list which will have checkboxes that allow you
I am trying to create a Custom List View Adapter by extending the ArrayList
I'm trying to create a custom control - a button - which will have
I am trying to create a list view which as TextView that can display
I am trying to create a custom ListView using an ArrayAdapter . POJO Item
I am trying to create a custom field type which will display values based
I am trying to create a custom view for a sharepoint list, similar to
I'm trying to create a custom Jinja variable that will cycle through a list

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.