我需要你的帮助!
在我的应用程序中,在GridView
. 单元格显示图像,而不是默认的R.id.noimage
和以前查看的图像。在我添加适配器以加载位图后出现此错误AsyncTask
。
我究竟做错了什么?
代码:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
View vi = null;
ImageView image;
if(convertView==null) {
vi = inflater.inflate(R.layout.gall_item, null);
Log.i("info","convertView==null");
} else {
vi = inflater.inflate(R.layout.gall_item, null);
Log.i("info","else");
}
holder.position = position;
image = (ImageView)vi.findViewById(R.id.img);
TextView url_img = (TextView)vi.findViewById(R.id.url_img);
TextView cer = (TextView)vi.findViewById(R.id.cer);
TextView idi = (TextView)vi.findViewById(R.id.ids);
url_img.setText(img2[position]);
cer.setText(cer_ar[position]);
idi.setText(id_ar[position]);
new LoadImageT(holder).execute(image, img1[position],activity.getApplicationContext(),position);
return vi;
}
class LoadImageT extends AsyncTask<Object, Void, Bitmap> {
Context context;
private ImageView imv;
private String url;
private Bitmap bitmap = null;
private int posS;
private ViewHolder mHolder;
public LoadImageT(ViewHolder holder) {
mHolder = holder;
}
@Override
protected Bitmap doInBackground(Object... params) {
imv = (ImageView) params[0];
url = (String) params[1];
context = (Context)params[2];
posS = (Integer) params[3];
bitmap = imageLoader.getBitmaptrue(url,imv,context);
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
if (mHolder.position == posS) {
imv.setVisibility(View.VISIBLE);
imv.setImageBitmap(result);
} else {
int stub_id = R.drawable.noimage;
imv.setImageResource(stub_id);
}
}
}