gpt4 book ai didi

android - Listview 上的通用图像加载器很慢

转载 作者:行者123 更新时间:2023-11-30 03:38:53 26 4
gpt4 key购买 nike

我已经确保我只有一个 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;

}

最佳答案

我认为您的问题不是 ImageLoader。事实上,您没有使用系统传回给您的 convertView,因此您根本没有回收 View ,您只是为列表的每一行增加一个新 View 。

尝试更改您的 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;

}

关于android - Listview 上的通用图像加载器很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16150589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com