2012-11-15 64 views
3

我使用的ListView在我application.But圖像的滾動期間顯示,每當我 滾動列表,錯誤的圖像顯示,然後再正確 圖像顯示。我不知道爲什麼會發生這種情況。我想 認爲已經加載的圖像顯示,直到設置位置。 這裏是我的適配器類,請幫我在哪裏,我錯了錯誤的圖像首先顯示,然後正確的圖像列表視圖

public class MySimpleArrayAdapter extends ArrayAdapter<String> { 
    private Activity context; 
    ArrayList<String> namear,msgar,idar,profimage,postimage,commentsnum,objectid,urlString; 
    ImageLoader imageLoader; 
    Bitmap[] bitdata; 

    public MySimpleArrayAdapter(Activity c,int i,ArrayList<String> postpic, ArrayList<String> names,ArrayList<String> msg,ArrayList<String> id,ArrayList<String> proimg,Bitmap[] bit,ArrayList<String> comment,ArrayList<String> objid,ArrayList<String> web) { 

     super(c, i, names); 
    Log.e("adapter","adap"); 
    this.context = c; 
    this.namear = names; 
    this.msgar = msg; 
    this.idar = id; 
    this.profimage=proimg; 
    this.postimage=postpic; 
    this.bitdata=bit; 
    this.commentsnum=comment; 
    this.objectid=objid; 
    this.urlString=web; 
    this.imageLoader = new ImageLoader(context); 
    } 

    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
    View rowView=convertView; 
    ViewHolder holder = new ViewHolder(); 
     if(convertView == null) { 
    LayoutInflater inflator = getLayoutInflater(); 
    rowView = inflator.inflate(R.layout.walldata, null); 

    holder.name1 = (TextView) rowView.findViewById(R.id.name); 
    holder.message1 = (TextView) rowView.findViewById(R.id.msg); 
    holder.profimg= (ImageView) rowView.findViewById(R.id.profile_pic); 
    holder.postimg= (ImageView) rowView.findViewById(R.id.picpost); 
    holder.comments = (TextView) rowView.findViewById(R.id.comment); 
    rowView.setTag(holder); 
    Log.e("user",idar.get(position)); 
     } 
     else 
     { 
      holder = (ViewHolder) rowView.getTag(); 
     } 
    Log.e("adapter","adap"); 
    holder.name1.setText(namear.get(position)); 
    if(msgar.get(position)!=""){ 
     holder.message1.setText(msgar.get(position)); 

    } 
    else 
    { 
     holder.message1.setVisibility(View.GONE); 
    } 
    if(!postimage.get(position).equals("")) 
    {try{ 
     imageLoader.DisplayImage(postimage.get(position).replace(" ", "%20"), holder.postimg) ; 

    } 
    catch(Exception e){ 
     e.printStackTrace(); 
    } 
    } 
    else 
    { 
     holder.postimg.setVisibility(View.GONE); 
    } 
    try{ 
     imageLoader.DisplayImage(profimage.get(position).replace(" ", "%20"), holder.profimg) ; 
    } 
    catch(Exception e){ 
     e.printStackTrace(); 
    } 

    holder.comments.setText(commentsnum.get(position)+"\t"+"Comments"); 
    holder.comments.setOnClickListener(new OnClickListener() { 


     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent myintent=new Intent(Wall.this,Comments.class); 
      myintent.putExtra("name", namear.get(position)); 
      myintent.putExtra("profimg", profimage.get(position)); 
      myintent.putExtra("message", msgar.get(position)); 
      myintent.putExtra("postpic", postimage.get(position)); 
      myintent.putExtra("objectid", objectid.get(position)); 
      myintent.putExtra("commentsnum",commentsnum.get(position)); 
      myintent.putExtra("webservice", urlString.get(position)); 
      startActivity(myintent); 

     } 
    }); 

    return rowView; 
    } 

} 
public class ViewHolder{ 
    TextView name1, message1,comments; 
    ImageView profimg,postimg; 
} 
+0

如果有人仍在尋找答案 - 嘗試此鏈接 http://stackoverflow.com/questions/18049785/listview-showing-wrong-view-for-a-few-seconds-while-flinging-and滾動 – yehudahs

回答

0

務必將您的ImageView圖像以儘早在getView方法空。由於ListView正在重新使用列表項目,因此將會顯示舊列表項目,直至設置新列表項目。

+0

當我向下滾動然後向上滾動時,已加載的圖像不會顯示,並且需要時間才能顯示 – veerendra

+0

如果您要下載圖像,則應該實施緩存以避免每次顯示時都下載它們。只需在本地讀取它們並將它們設置爲ImageView速度非常快。 – TofferJ

+0

我工作在不同的方法,沒有采取任何這些持有人類和什麼都沒有,我在快速滾動listview – veerendra