2013-06-01 50 views
-1

我想在自定義適配器的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);   

    } 

回答

0

我不能讓你的問題正確,直到您提供更多的代碼。 它沒有被正確描述。 你必須正確描述它,或向我們顯示登錄貓的錯誤,或者你在這個任務中遇到的問題! 從代碼我可以說你正在使用異步任務,所以在異步任務中有太多重要的事情發佈後的任務,或者當你想更新UI使用「publishProgress();」。

我還分享了一些鏈接,可以幫助你在這! http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/ http://www.androidhive.info/2012/07/android-loading-image-from-url-http/ http://mobile.tutsplus.com/tutorials/android/android-sdk-displaying-images-with-an-enhanced-gallery/ http://developer.android.com/reference/android/os/AsyncTask.html http://www.javasrilankansupport.com/2012/11/asynctask-android-example-asynctask-in.html

相關問題