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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:31:21+00:00 2026-05-24T00:31:21+00:00

i need to list out data from net in that i have 1 image

  • 0

i need to list out data from net in that i have 1 image and 2 text. i parse all data and display it but the image displaying very slow in list. so i m looking for best way to do this.

Please help me out.

Thanks In Advance

  • 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-24T00:31:22+00:00Added an answer on May 24, 2026 at 12:31 am

    Please copy the below class . That class is download the images from the web and stores into the
    memory card or into internal memory of application .

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URL;
    import java.util.HashMap;
    import java.util.Stack;
    
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.widget.ImageView;
    
    public class Imageloader 
    {
        // the simplest in-memory cache implementation. This should be replaced with
        // something like SoftReference or BitmapOptions.inPurgeable(since 1.6)
    
        private HashMap<String, Bitmap> cache = new HashMap<String, Bitmap>();
    
        private File cacheDir = null;
        private Bitmap  useThisBitmap = null;
        @SuppressWarnings("unused")
        private Context ctx = null;
    
        public Imageloader(Context context) 
        {
            // Make the background thead low priority. This way it will not affect
            // the UI performance
    
            ctx = context;
            photoLoaderThread.setPriority(Thread.NORM_PRIORITY - 1);
    
            // Find the dir to save cached images
            if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
                cacheDir = new File(android.os.Environment.getExternalStorageDirectory(),"DownloadImages/AlbumArt/");
            else
                cacheDir = context.getCacheDir();
    
            if (!cacheDir.exists())
                cacheDir.mkdirs();
        }
    
        public void DisplayImage(String url, Activity activity, ImageView imageView) 
        {
            if(!url.equals(""))
             {
                 if (cache.containsKey(url))
                 {
                     imageView.setImageBitmap(cache.get(url));
                 }
                 else
                 {
                    queuePhoto(url, activity, imageView);
                }
             }
        }
    
        private void queuePhoto(String url, Activity activity, ImageView imageView) 
        {
            // This ImageView may be used for other images before. So there may be
            // some old tasks in the queue. We need to discard them.
    
            photosQueue.Clean(imageView);
            PhotoToLoad p = new PhotoToLoad(url, imageView);
    
            synchronized (photosQueue.photosToLoad) 
            {
                photosQueue.photosToLoad.push(p);
                photosQueue.photosToLoad.notifyAll();
            }
    
            // start thread if it's not started yet
            if (photoLoaderThread.getState() == Thread.State.NEW)
                photoLoaderThread.start();
        }
    
        public Bitmap getBitmap(String url) 
        {
            try
            {
                // I identify images by hashcode. Not a perfect solution, good for the
                // demo.
                String filename = String.valueOf(url.hashCode());
                File f = new File(cacheDir, filename);
    
                // from SD cache
                Bitmap b = decodeFile(f);
                if (b != null)
                    return b;
    
                // from web
                try {
                    Bitmap bitmap = null;       
                    if(!url.equals("")){
                    InputStream is = new URL(url).openStream();
                    OutputStream os = new FileOutputStream(f);
                    Utils.CopyStream(is, os);
                    os.close();
                    bitmap = decodeFile(f);
                    }
                    return bitmap;
                } 
                catch (Exception ex) 
                {
                    ex.printStackTrace();
                return null;
                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
    
                return null;    
            }
        }
    
        /*decodes image and scales it to reduce memory consumption
         * @param file path
         * @throws FileNotFoundException
         * @return bitmap
         * */
        private Bitmap decodeFile(File f){
            Bitmap b = null;
            try {
    
                useThisBitmap = null;
                //Decode image size
                BitmapFactory.Options o = new BitmapFactory.Options();
                o.inJustDecodeBounds = true;
                final int IMAGE_MAX_SIZE = 70;
                BitmapFactory.decodeStream(new FileInputStream(f), null, o);
                int scale = 2;
                if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
                    scale = 2 ^ (int) Math.ceil(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5));
                }
    
                //Decode with inSampleSize
                BitmapFactory.Options o2 = new BitmapFactory.Options();
    
                o2.inSampleSize = scale;
                b = BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
                useThisBitmap = b;
    
            } 
            catch (FileNotFoundException e) {
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            finally
            {
                System.gc();
            }
            return useThisBitmap;
        }
    
    
        // Task for the queue
        private class PhotoToLoad 
        {
            public String url;
            public ImageView imageView;
    
            public PhotoToLoad(String u, ImageView i) {
                url = u;
                imageView = i;
            }
        }
    
        private PhotosQueue photosQueue = new PhotosQueue();
    
    
    
        // stores list of photos to download
        private class PhotosQueue 
        {
            private Stack<PhotoToLoad> photosToLoad = new Stack<PhotoToLoad>();
            // removes all instances of this ImageView
            private void Clean(ImageView image) 
            {
                for (int j = 0; j < photosToLoad.size();) 
                {
                    if (photosToLoad.get(j).imageView == image)
                        photosToLoad.remove(j);
                    else
                        ++j;
                }
            }
        }
    
        private class PhotosLoader extends Thread 
        {
            public void run() 
            {
                try 
                {
                    while (true) 
                    {
                        // thread waits until there are any images to load in the
                        // queue
                        if (photosQueue.photosToLoad.size() == 0)
                            synchronized (photosQueue.photosToLoad) {
                                photosQueue.photosToLoad.wait();
                            }
                        if (photosQueue.photosToLoad.size() != 0) {
                            PhotoToLoad photoToLoad;
                            synchronized (photosQueue.photosToLoad) {
                                photoToLoad = photosQueue.photosToLoad.pop();
                            }
                            Bitmap bmp = getBitmap(photoToLoad.url);
                            cache.put(photoToLoad.url, bmp);
                            if (((String) photoToLoad.imageView.getTag())
                                    .equals(photoToLoad.url)) {
                                BitmapDisplayer bd = new BitmapDisplayer(bmp,
                                        photoToLoad.imageView);
                                Activity a = (Activity) photoToLoad.imageView
                                        .getContext();
                                a.runOnUiThread(bd);
                            }
                        }
                        if (Thread.interrupted())
                            break;
                    }
                } catch (InterruptedException e) {
                    // allow thread to exit
                }
            }
        }
    
        private PhotosLoader photoLoaderThread = new PhotosLoader();
    
        // Used to display bitmap in the UI thread
        private class BitmapDisplayer implements Runnable 
        {
            private Bitmap bitmap;
            private ImageView imageView;
    
            private BitmapDisplayer(Bitmap b, ImageView i) 
            {
                bitmap = b;
                imageView = i;
            }
    
            public void run() 
            {
                if (bitmap != null)
                    imageView.setImageBitmap(bitmap);
            }
        }
    
        public void stopThread() 
        {
            photoLoaderThread.interrupt();
        }
    
        public void clearCache() 
        {
            cache.clear();
            File[] files = cacheDir.listFiles();
            for (File f : files)
                f.delete();
        }
    }
    

    Example

    First create your image Loader class object.

    Imageloader imageLoader = new Imageloader(getApplicationContext());
    

    then set the image url into the imageview’s setTag Property.

    imgImageView.setTag(Your Image Url);
    

    then call your ImageLoader class Display image function . There are 3 parameters required.

    1) Image Url

    2) Your Current Class Name

    3) ImageView

    imageLoader.DisplayImage(Your Image Url,ClassName.this,imgImageView);
    

    this functon dowload images from the web and stored into the memory and show from the memory.

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

Sidebar

Related Questions

I have some text i need to filter out a list of bad words
From the following HTML I need to figure out which List tag has class
I have list of catalog paths and need to filter out some of them.
I need to return a list of counties, but I need to filter out
I need to list all files whose names start with 'SomeLongString'. But the case
I have a List<InputField> but I need a List<IDataField> Is there a way to
I have an ASP.NET web app that places several string data into an object
I have an application that extracts data from some xml that is stored in
I've got a .NET MVC app where I need to display a list of
i have line by line data in a table and i need to net

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.