0

what i have is a grid view and i open the images online . but what i need to do is when the user open the app .. all of those images to be downloaded in the mobile phone automatically so when the user open the app again it will show up from the memory not online ..

please any help?? and what i have is 250 images maybe 

and is there any other so i can call my images dynamically instead of calling them one by one??

here is an example of how i call my images:

private String urls[] = { 
            "http://transition-se.com/training_may/foodribbons.JPG",
            "http://transition-se.com/training_may/clothribbon.JPG",
            "http://transition-se.com/training_may/shoesribbon.JPG",
            "http://transition-se.com/training_may/bagsribbon.JPG",
            "http://transition-se.com/training_may/viewsribbon.JPG",
            "http://transition-se.com/training_may/makeupribbon.JPG",
            "http://transition-se.com/training_may/roomribbon.JPG",
            "http://transition-se.com/training_may/watchesribbon.JPG"



    };
user3675605
  • 39
  • 2
  • 11

1 Answers1

0

You can do it like a hard way, or you can do it easy way. You can make symple Asynk task and load images to files on your device.

Example:

private class Downloader extends AsyncTask<String, Void, Integer> {

    @Override
    protected void onPreExecute() {
        // show dialog loading here
    }

    @Override
    protected Integer doInBackground(String... params) {
        // for loop here
        for(int i=0; i<params.lenght; i++) {
            try {
                URL url = new URL(params[i]);
                InputStream is = url.openStream();
                OutputStream os = new FileOutputStream( file name here );
                // add this file to global list, so you can used it after

                byte[] b = new byte[1024];
                int length;

                while ((length = is.read(b)) != -1) {
                    os.write(b, 0, length);
                }

                is.close();
                os.close();

                return 1;

            } catch (Exception e) {
                e.printStackTrace();
            }

            return 0;
        }
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        // update loading dialog precents
    }

    @Override
    protected void onPostExecute(Integer result) {             
        // hide loading dialog

        if (result == 1) {
            // all images loaded to files
        }
    }
}

Or you can use out of the box libs for this operation which i prefer, try this Picasso Asynk image loader, it will handle complex operation for you

  • Handling ImageView recycling and download cancelation in an adapter.
  • Complex image transformations with minimal memory use.
  • Automatic memory and disk caching.
Vasil Valchev
  • 5,701
  • 2
  • 34
  • 39
  • ok but can i load all of the images in some folder dynamically ?? – user3675605 Jun 25 '14 at 10:35
  • yes you can, search here for examples, here it is one http://stackoverflow.com/questions/8493642/creating-folder-in-internal-memory-to-save-files-and-retrieve-them-later – Vasil Valchev Jun 25 '14 at 11:06