1

in my app i use grid view .it works fine with image taken from res folder. but my need is i have to display images in grid view from n number of urls. my problem is how to set string path(url) to imageView.setImageResource(). this function only take drawable resid. that is my problem.

i get the code from http://developer.android.com/guide/tutorials/views/hello-gridview.html

code:

  public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]); **// here i have to give string url**
    return imageView;
}

// references to our images             **// here i have to store image url as string of array**
private Integer[] mThumbIds = {
        R.drawable.a, R.drawable.b,
        R.drawable.c, R.drawable.d
};
M.A.Murali
  • 9,988
  • 36
  • 105
  • 182

1 Answers1

0

ImageView has a method setImageURI that lets you pass a URI to be the content of the view.

John Flatness
  • 32,469
  • 5
  • 79
  • 81
  • hi i tried in the following way what you told, but i get a image with green color. Uri uri=Uri.parse(mThumbIds[position]); imageView.setImageURI(uri); but in the url i have real photos. please help me. – M.A.Murali May 28 '11 at 07:20
  • You could alternatively use [BitmapFactory](http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeFile(java.lang.String)) and [setImageBitmap](http://developer.android.com/reference/android/widget/ImageView.html#setImageBitmap(android.graphics.Bitmap)) but it should be basically equivalent. – John Flatness May 28 '11 at 07:40