1

我已经确保我只有一个 ImageLoader 实例,所以我知道这不是问题,由于某种原因,它只会在显示从网络加载的全新图像时滞后。所以我假设它与 UI 卡顿的事实有关,因为它正在解码图像,但我虽然 Universal Image Loader 异步处理了所有事情。这是我的 BaseAdapter 的 getView 方法的内容。

@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;

}
4

1 回答 1

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;

}
于 2013-04-22T15:25:50.163 回答