2013-04-22 19 views
1

我确定我只有一个ImageLoader实例,所以我知道这不是问题,因为某些原因,它只在显示从网络加载的全新图像时才会出现问题。所以我认为它与UI的口吃有关,因为它解码图像,但我通过Universal Image Loader异步处理所有内容。这是我的BaseAdapter的getView方法。Listview上的通用图像加载器是laggy

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

    LayoutInflater inflater = (LayoutInflater) mContext 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    JSONObject thePost = null; 
    try { 
     thePost = mPosts.getJSONObject(position).getJSONObject("data"); 
    } catch (Exception e) { 
     System.out.println("errreoroer"); 
    } 

    LinearLayout postItem = (LinearLayout) inflater.inflate(R.layout.column_post, parent, false); 

    String postThumbnailUrl = null; 


    try { 

     //parse thumbnail 
     postThumbnailUrl = thePost.getString("thumbnail");   

    } catch (Exception e) {}   

    //grab the post view objects 

    ImageView postThumbnailView = (ImageView)postItem.findViewById(R.id.thumbnail); 

    if (!(postThumbnailUrl.equals("self") || postThumbnailUrl.equals("default") || postThumbnailUrl.equals("nsfw"))) 
     mImageLoader.displayImage(postThumbnailUrl, postThumbnailView);   


    return postItem; 

} 
+0

[这个I/O通话(http://youtu.be/wDBM6wVEO70)中含有宝贵的洞察的ListView的话题(和其中大部分适用于其他AdapterViews)我强烈建议您观看本次演讲,以便了解推动优化的机制。 – FoamyGuy 2013-04-22 15:43:26

回答

1

我认为你的问题不是ImageLoader。事实上,你并没有使用系统传回给你的convertView,所以你根本没有回收视图,你只需要为列表中的每一行添加一个新的视图。

试着改变你的getView()方法利用convertView的:

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    LinearLayout postItem = convertView 
    if(null == postItem){ 
     LayoutInflater inflater = (LayoutInflater) mContext 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     postItem = (LinearLayout) inflater.inflate(R.layout.column_post, parent, false); 
    } 

    JSONObject thePost = null; 
    try { 
     thePost = mPosts.getJSONObject(position).getJSONObject("data"); 
    } catch (Exception e) { 
     System.out.println("errreoroer"); 
    } 
    String postThumbnailUrl = null; 
    try { 

     //parse thumbnail 
     postThumbnailUrl = thePost.getString("thumbnail");   

    } catch (Exception e) {}   

    //grab the post view objects 
    ImageView postThumbnailView = (ImageView)postItem.findViewById(R.id.thumbnail); 
    if (!(postThumbnailUrl.equals("self") || postThumbnailUrl.equals("default") || postThumbnailUrl.equals("nsfw"))) 
     mImageLoader.displayImage(postThumbnailUrl, postThumbnailView);   

    return postItem; 

} 
+1

这就是问题所在!非常感谢你,救了我很头疼。 – vivatus 2013-04-22 15:39:04

相关问题