slider

还是菜鸟
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

android: adapter getView(position==0) was invoked many times.

Posted on 2013-07-24 10:34  slider  阅读(861)  评论(0编辑  收藏  举报

  this is a big problem for me. i follow the solutions that i  searched from the internet: modify the listview layout and list-item layou file, 'wrap_content' to 'fill_parent'. but 'getView' function always was voked many time when the value of the 'position' is 0; i think it is maybe due to my complexed layout file.  so , i decide to give the a special way to load the data when 'position ' was 0; my solution like this:

if(position==0){
            Bitmap bitmap = null;
            if(imageFetcher.mImageCache!=null){
                bitmap = imageFetcher.mImageCache.get(entity.getPath());
                if(bitmap!=null){
                    holder.imageView.setImageBitmap(bitmap);
                }else {
                    bitmap = FileImageUtil.getImageLocal(entity.getPath(), 100, 100);
                    if(bitmap != null){
                        imageFetcher.mImageCache.put(entity.getPath(), bitmap);
                        holder.imageView.setImageBitmap(bitmap);
                    }else {
                        holder.imageView.setImageResource(R.drawable.image_broken);
                    }
                }
            }
        }else {
            Log.d(TAG, "load position "+(position)+" ----- path "+entity.getPath()+" convertView "+convertView+" imageview " + holder.imageView);
            imageFetcher.loadBitmap(entity.getPath(), (position), 100, 100, holder.imageView);
        }

it works fine.