如果是本地的,则从URL加载图像

时间:2013-09-02 11:12:38

标签: android

我已成功设置从drawable目录(本地)成功加载图像,我正在考虑更改它,以便它将从Web加载图像。

我在GridView中显示图像,我需要对代码进行哪些操作才能从网上加载它们?

任何帮助都将不胜感激,谢谢。

适配器:

package com.question;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class AdapterViewADV extends BaseAdapter {
private Context mContext;


public Integer[] mThumbIds = {
    R.drawable.Image1,
    R.drawable.Image2,
    R.drawable.Image3,
    R.drawable.Image4,
    R.drawable.Image5,
    R.drawable.Image6

};


public AdapterViewADV(Context c){
mContext = c;
}

@Override
public int getCount() {
    return mThumbIds.length;
}

@Override
public Object getItem(int position) {
return mThumbIds[position];
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(NO_SELECTION, NO_SELECTION));
return imageView;
}

}