グリッドビューを作成し、URL からこのグリッドビューにいくつかの画像を読み込もうとしていますが、画像の読み込みに問題がありますが、見つかりません。誰か助けてもらえますか?
package com.images;
import java.io.InputStream;
import java.net.URL;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.coboltforge.slidemenuexample.MainActivity;
import com.coboltforge.slidemenuexample.R;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
// Keep all Images in array
public Integer[] mThumbIds = new Integer [27];
// Constructor
public ImageAdapter(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(130, 130));
* return imageView;
*/
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(150, 150));
imageView.setAdjustViewBounds(false);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
for (int i = 0; i < MainActivity.presentersImages.size(); i++) {
imageView
.setImageDrawable(LoadImageFromWebOperations(MainActivity.presentersImages
.get(i) + position));
}
return imageView;
}
protected Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
System.exit(0);
return null;
}
}
}
MainActivity.presentersImages は、画像の URL を含む文字列の ArrayList です。