zoukankan      html  css  js  c++  java
  • android: adapter getView(position==0) was invoked many times.

      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.

  • 相关阅读:
    OC 消息机制本质
    Lua中的闭包
    Lua中的函数
    Lua中的语句
    Lua中的表达式
    Lua中的类型与值
    Unity3D之通过C#使用Advanced CSharp Messenger
    C#中sealed关键字
    C#委托delegate、Action、Func、predicate 对比用法
    Unity3D之IOS&Android收集Log文件
  • 原文地址:https://www.cnblogs.com/slider/p/3210080.html
Copyright © 2011-2022 走看看