2013-08-20 1 views
0

에로드되었을 때 나는이 문제에 대한 약간의 설명을하고 싶은 이미지 뷰를 다시로드하지 마십시오. listview의 각 항목에는 URL의 이미지로 채워지는 이미지 뷰가 있습니다.안드로이드 : 나는 목록보기를 만든</p> <p>: 이미 목록보기

내가 목록 아래로 스크롤하면 항목이 나타날 때, 각각의 이미지가로드 => OK

내가 스크롤 때, 이전에로드 된 이미지를 다시 다운로드됩니다.

어떻게하면이 동작을 멈출 수 있습니까? 여기

내 다운로더의 코드입니다 :

public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { 
     ImageView bmImage; 

     public DownloadImageTask(ImageView bmImage) { 
      this.bmImage = bmImage; 
     } 

     protected Bitmap doInBackground(String... urls) { 
      String urldisplay = urls[0]; 
      Bitmap mIcon11 = null; 
      try { 
       InputStream in = new java.net.URL(urldisplay).openStream(); 
       mIcon11 = BitmapFactory.decodeStream(in); 
      } catch (Exception e) { 
       Log.e("Error", e.getMessage()); 
       e.printStackTrace(); 
      } 
      return mIcon11; 
     } 

     protected void onPostExecute(Bitmap result) { 
      bmImage.setImageBitmap(result); 
     } 
    } 

을 그리고 여기 내 어댑터의 코드 조각입니다 :

@Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     Activity activity = (Activity) getContext(); 

     LayoutInflater inflater = activity.getLayoutInflater(); 

     View rowView; 
     ArticleHome article = getItem(position); 


     if (position == 0) { 
      rowView = inflater.inflate(R.layout.item_ligne_home_premier, null); 
      new DownloadImageTask((ImageView) rowView.findViewById(R.id.imgimg)).execute(article.getImage()); 
      TextView textView = (TextView) rowView.findViewById(R.id.titlenew); 
      textView.setText(article.getTitle()); 
      textView.setTypeface(faceLight); 
     } 
     else { 
      rowView = inflater.inflate(R.layout.item_ligne_home, null); 
      new DownloadImageTask((ImageView) rowView.findViewById(R.id.imgimg)).execute(article.getImage()); 
      TextView title = (TextView) rowView.findViewById(R.id.titlearticleothers); 
      title.setText(article.getTitle()); 
      title.setTypeface(faceBold); 
      TextView desc = (TextView) rowView.findViewById(R.id.descriptionarticleothers); 
      // Add test si < a une certaine longeuryr 
      desc.setText(article.getDescription().substring(0, 100)); 
      desc.setTypeface(faceLight); 
     } 


//  img.setImageAlpha(1680); 
//  img.setImageAlpha(1880); // Pasmal plus haut plus foncé 


     return rowView; 

    } 
+1

이미지 캐싱 .... [참조] (http://stackoverflow.com/a/7861011/2345913) – CRUSADER

답변

0

실제로 그것에 대해 이동하는 방법은 각 이미지 당신을 캐시하는 것입니다 다운로드하여 ListView 항목을 캐시의 이미지로 업데이트하고 이미지가 캐시에없는 경우에만 다운로드하십시오.

이렇게하면 다운로드가되지 않습니다.

확인 Pramod J George하여이 대답, 특히하여 ImageLoader 클래스입니다.

관련 문제