慢加载GridView

时间:2013-11-12 17:29:11

标签: android multithreading performance gridview

我有一个加载一些图像的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;
}

0 个答案:

没有答案