简体   繁体   中英

How to retrieve multiple images from server in android?

I am a fresher in android developing.I want to retrieve multiple images from server and set Id for all images,Then dynamically give id and show the responsible images.This is my task.I have done to retrieved single images from server. I have insert coding below. I tried to retrieve multiple images from server.But i was confused can't get clear idea.so anybody can help me please give some idea. Advanced thank you.

public class MainActivity extends Activity {


    ImageView   img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img     =   (ImageView) findViewById(R.id.imageView1);
        new Image_Async().execute();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    class Image_Async extends AsyncTask<Bitmap,Bitmap,Bitmap>
    {

        @Override
        protected Bitmap doInBackground(Bitmap... arg0) {
            // TODO Auto-generated method stub
            Bitmap  bmp=    null;
            try {
                URL url =   new URL("http://blog.gettyimages.com/wp-content/uploads/2013/01/Siberian-Tiger-Running-Through-Snow-Tom-Brakefield-Getty-Images-200353826-001.jpg");
                try {

                    bmp =   BitmapFactory.decodeStream(url.openConnection().getInputStream());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return bmp;
        }

        @Override
        protected void onPostExecute(Bitmap result) {
            // TODO Auto-generated method stub
            img.setImageBitmap(result);
            super.onPostExecute(result);
        }

    }

I would suggest you to look into either of any Asynchronous image loading library exists on web.

Check:

  1. Universal Image Loader
  2. Picasso

I am suggesting you to use either of above library because it would help you to load multiple image asynchronously, as well as it manages image caching, and for that you don't to need to write any code, just load a image into ImageView and enjoy!

I have used this in the past.

http://loopj.com/android-smart-image-view/

This makes it very easy to load images from a website in Android.

In my application I download all the images from same url.

I think you want all images .

for refer this Link might help.

If your Idea is Like that then I'll Give you the Library file link and the class file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM