我有一个加载一些图像的 GridView。我在 GetView (在 Adapter 类上)上放了一个 log 方法,我意识到这个方法的执行次数比图像的数量还要多。执行一个线程来获取 GetView 上的图像。我认为如果只为每个图像调用一次 GetView,则 Grid 加载速度会更快。我对么?有没有办法做到这一点?
这是我的GetView:
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout layout = (RelativeLayout) convertView;
ViewHolder view;
PMCategory category = categoriesArray.get(position);
RewardImageLazyLoadingThread rewardImageLazyLoader = new RewardImageLazyLoadingThread();
if (layout == null) {
layout = (RelativeLayout) inflater.inflate(
R.layout.reward_item_image, parent, false);
view = new ViewHolder();
view.reward_imageView = (ImageView) layout
.findViewById(R.id.reward_image);
layout.setTag(view);
} else {
view = (ViewHolder) layout.getTag();
}
if (position > CurrPosition) //To throw the thread only once for each image
{
positionAtual = position;
rewardImageLazyLoader.setProperties(category.id, view);
rewardImageLazyLoader.execute();
}
return layout;
}