0

I displayed images to the gallery view with images in drawable folder. MyCode

public class GalleryView extends Activity {
Integer[] pics = {
  R.drawable.antartica1,
  R.drawable.antartica2,
  R.drawable.antartica3,
  R.drawable.antartica4,
  R.drawable.antartica5,
  R.drawable.antartica6,
  R.drawable.antartica7,
  R.drawable.antartica8,
  R.drawable.antartica9,
  R.drawable.antartica10
};
ImageView imageView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Gallery ga = (Gallery)findViewById(R.id.Gallery01);
    ga.setAdapter(new ImageAdapter(this));

    imageView = (ImageView)findViewById(R.id.ImageView01);
    ga.setOnItemClickListener(new OnItemClickListener() {



public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
 long arg3) {
Toast.makeText(getBaseContext(), 
  "You have selected picture " + (arg2+1) + " of Antartica", 
  Toast.LENGTH_SHORT).show();
imageView.setImageResource(pics[arg2]);

}

    });

}



}

But I have images in an arraylist like this

[http://sport24x7.com/nightclub/photos/ 9955917512-Gym-ChestWorkout_xxlarge.jpg, http://sport24x7.com/nightclub/photos/ 64557264beginner_gym_workout_legs_large.jpg, http://sport24x7.com/nightclub/photos/ 54809160intro-ez-bar.jpg]

How to show these images in gallery view. Can anyone help me to do this?

Hanzs
  • 25
  • 3

3 Answers3

0

you should download images and then display them with Gallery.
i recommend you to use UIL

ReZa
  • 1,273
  • 2
  • 18
  • 33
0

Note that Gallery view is deprecated and shouldn't be used anymore.

Here is a simple tutorial on how to use GridView to display images.

The key concept is to override getView and load your images into the ImageView. You can easily load the images given the URL using Picasso.

For example in your Adapter's getView:

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
SteD
  • 13,909
  • 12
  • 65
  • 76
0

Download the image from the web and convert the stream to Bitmap

Try the below code.

URL imageUrl = new URL(item);
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);

I would suggest lazy loading. Try Universal Image Loader

Vinothkumar Arputharaj
  • 4,567
  • 4
  • 29
  • 36