我想在自定义适配器的 getview 方法中动态创建一个图像视图,以在列表视图中显示下载的图像。但图像不显示。
我的一段代码是
public View getView(int position, View convertView, ViewGroup parent) {
inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
imageview = new ImageView(getApplicationContext());
if (convertView == null){
convertView = inflater.inflate(R.layout.show_image, null);
imageview.setLayoutParams(new LayoutParams(50,50));
imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageview.setVisibility(ImageView.VISIBLE);
convertView.setTag(imageview);
progress.setVisibility(progress.VISIBLE);
new DownloadTask().execute(images.get(position), imageview);
}else{
new DownloadTask().execute(images.get(position), imageview);
return convertView;
}
return convertView;
}
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
iv.setImageBitmap(result);
}