开发者

how to set string path instead of resource id from res folder in android

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 = {
   开发者_C百科     R.drawable.a, R.drawable.b,
        R.drawable.c, R.drawable.d
};


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜