2.png 1.png

위의 두 스샷을 보면 첫이미지가 달라졌습니다

처음에 로드하면 1번화면이 나오고 스크롤도 잘됩니다

헌데 스크롤을 잠깐 내렸다가 올리면
   (TEXT옆에 숫자가 써있는데  position 번호입니다)

10번 포지션에 나와야 할 이미지가 0번 포지션에 다시 뿌려 주더라고요
(2번포지션에 이미지도 다시 스크롤ㄹ을 내리면 12번에 이미지가 뿌려져있습니다)

그리고 다시 스크롤을 이동하면 정상으로 돌아갑니다

문제는 스크롤을 재빨리 내렸다가 올리면 새로 Thread가 생성되어 받은 이미지가

상위에 잠깐 생기는 것입니다

천천히 할때는 상관없지만 빠르게 하면 문제가 생기는 것 같습니다

로그를 찍어서 확인해보니 스크롤을 쭉내리면

0번포지션과 10번포지션의 이미지 객체가 다른데

스크롤을 내렸다가 빨리 다시 올리면 이미지 객체가 같아서 그런듯 합니다

지금 3주일째 이거 하고 있습니다 -_-;;;;;

답이 안나오네요  어떻게 처리해야하나요??

현상황에 대한 해결 책을 아시면 답변 부탁드리겠습니다

아!! 이미지는 getView에서 해당position값을 가져와 Thread로 각각 받아와 뿌려주는 방식입니다


밑에는 참고 소스입니다

===adapter 및 getView=======================
class MyListAdapter extends ArrayAdapter {
  ArrayList<MyItem> arrMyItem;
  Context maincon;
  LayoutInflater Inflater;//XML로 만든 뷰를 자바 클래스로 쓸수있게 바꿔준다 
  public MyListAdapter(Context context, int textViewResourceId,
    ArrayList<MyItem> _arrMyItem) {
   super(context, textViewResourceId, _arrMyItem);
   this.arrMyItem = _arrMyItem;
   Log.e("", "arrMyItem.size : "+arrMyItem.size());
   this.maincon = context;
   Inflater = (LayoutInflater) context
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  } 

public View getView(int position, View convertView, ViewGroup parent) {
   View v = convertView;
   
   if (v == null) {
    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = vi.inflate(R.layout.row, null);
   }
   getMyItem = new MyItem();
   getMyItem = (MyItem) arrMyItem.get(position); 
   
 if (getMyItem != null) {
    tv = (TextView) v.findViewById(R.id.title);
    iv = (ImageView) v.findViewById(R.id.thumb);
//    System.out.println("zz : "+arrMyItem.get(position).iv+" position : "+position);//여기서 iv가 null 인데 바로 밑에서는 iv가 나온다
    
    if(getMyItem!=null){
     System.out.println(position+"====================");
     tv.setText(getMyItem.title+ " : "+position);
     
     if(position<10){
      System.out.println("arrMyItem.get("+position+").iv  : "+arrMyItem.get(position).iv);
      System.out.println("arrMyItem.get("+(position+10)+").iv : "+arrMyItem.get(position+10).iv);
      
      System.out.println("arrMyItem.get("+position+").thumbnail  : "+arrMyItem.get(position).thumbnail);
      System.out.println("arrMyItem.get("+(position+10)+").thumbnail : "+arrMyItem.get(position+10).thumbnail); 
     }else{
      System.out.println("arrMyItem.get("+position+").iv  : "+arrMyItem.get(position).iv);
      System.out.println("arrMyItem.get("+(position-10)+").iv : "+arrMyItem.get((position-10)).iv);
      
      System.out.println("arrMyItem.get("+position+").thumbnail  : "+arrMyItem.get(position).thumbnail);
      System.out.println("arrMyItem.get("+(position-10)+").thumbnail : "+arrMyItem.get(position-10).thumbnail);
     }
     
      if (arrMyItem.get(position).Drawable_thumbnail != null) {
       iv.setImageDrawable(getMyItem.Drawable_thumbnail);
       System.out.println("iv : "+iv);
      }
       else {
        System.out.println("iv : "+iv+" Nothing Drawable_thumbnail : ");
       iv.setImageResource(R.drawable.icon);
       getMyItem.iv=iv;
//       System.out.println("xx : "+arrMyItem.get(position).iv+" position : "+position);//여기서 iv가 null 인데 바로 밑에서는 iv가 나온다
       System.out.println();
       dm.fetchDrawableOnThread(arrMyItem, getMyItem.iv , position);
       
      } 
     
     System.out.println("====================");
     System.out.println("  ");
    }
}
   return v;
  }

===DrawableManager=============================
class DrawableManager {
 private final Map drawableMap;
 boolean ivflag=false;
 public DrawableManager() {
  drawableMap = new HashMap<String, SoftReference<Drawable>>();
 }
public Drawable fetchDrawable(String urlString , int position) {
  SoftReference<Drawable> drawableRef = (SoftReference<Drawable>) drawableMap
    .get(urlString);
  if (drawableRef != null) {
   Drawable drawable = drawableRef.get();
   if (drawable != null)
    return drawable;
   // Reference has expired so remove the key from drawableMap
   drawableMap.remove(urlString);
  }
  try {
   
   InputStream is = fetch(urlString);
   Drawable drawable = Drawable.createFromStream(is, "src");
   drawableRef = new SoftReference<Drawable>(drawable);
   drawableMap.put(urlString, drawableRef);
   return drawableRef.get();
  } catch (MalformedURLException e) {
   Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
   return null;
  } catch (IOException e) {
   Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
   return null;
  }
 }
public void fetchDrawableOnThread(ArrayList<MyItem> _arr_MyItem,
   ImageView _imageView, int _position) {
//  Log.e("","fetchDrawableOnThread ");
  final ArrayList<MyItem> arrMyItem;
  final int position = _position;
  final ImageView imageView = _imageView;
  System.out.println("into imageView "+imageView+" position : "+position);
  arrMyItem=_arr_MyItem;
  SoftReference<Drawable> drawableRef = (SoftReference<Drawable>) drawableMap
    .get(arrMyItem.get(position).thumbnail);
  

  //     
  final Handler handler = new Handler() {
   @Override
   public void handleMessage(Message message) {
    System.out.println("Handler ************************");
    System.out.println("iv :  "+imageView+ " position : "+position);
    System.out.println("arrMyItem.get(position).Drawable_thumbnail : "+arrMyItem.get(position).Drawable_thumbnail);
    System.out.println("************************");
    System.out.println("  ");
    
    imageView.setImageDrawable((Drawable) message.obj); 
//    Log.e("handler" , "out imageView : "+imageView.getDrawable());
   }
  };
Thread thread = new Thread() {
   
   @Override
   public void run() {
    try {
     Thread.sleep(200);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
//    Log.d("Thread RUN" , "Thread RUN into position : "+position);
    //thumbnail URL String 주소를 가지고 drawable을 만들어 객체에 저장
    Drawable drawable = fetchDrawable(arrMyItem.get(position).thumbnail , position);
    arrMyItem.get(position).Drawable_thumbnail = drawable;
    Message message = handler.obtainMessage(1, arrMyItem.get(position).Drawable_thumbnail);
//    System.out.println("into drawble : "+arrMyItem.get(position).Drawable_thumbnail+" position "+position);
//    System.out.println("into imageView "+imageView+" position : "+position);
    handler.sendMessage(message);
   }
  };
  thread.start();
 }
private InputStream fetch(String urlString) throws MalformedURLException,
   IOException {
  try {
   URL aURL = new URL(urlString);
   final URLConnection conn = aURL.openConnection();
   conn.connect();
   final BufferedInputStream bis = new BufferedInputStream(conn
     .getInputStream());
   return bis;
  } catch (Exception e) {
   Log.d("DEBUGTAG", "Oh noooz an error...");
  }
  return null;
 }
}