我想在自定義適配器的getview方法中動態創建一個imageview,以在列表視圖中顯示下載的圖像。但圖像不顯示。在自定義圖像適配器的getview方法中動態創建imageview
我這段代碼是
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);
}