适配器通知不起作用

时间:2014-02-17 01:00:26

标签: java android listview asynchronous adapter

我在我的适配器上异步加载图像。 但是在设置图像(位图)时,listview中没有任何反应。 任何想法有什么不对?

提前致谢

这是我用代码更新对象的代码(在适配器中):

public void setImage(int position ,Bitmap bm){
    profielen.get(position).setThumbNail(bm);
    this.notifyDataSetChanged();

}

适配器:

public class LeaderBoardAdapter extends ArrayAdapter<Profile>{

LayoutInflater vi;
List<Profile> profielen;
Context mContext;
int res;
public LeaderBoardAdapter(Context context, int resource,
        List<Profile> objects) {
    super(context, resource, objects);
    this.res = resource;
    this.profielen = objects;
    mContext = context;
    vi = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub


    ProfileHolder holder = null;
    if(convertView == null)
    {
        LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
        convertView = vi.inflate(R.layout.item_layout, parent, false);
        convertView = inflater.inflate(res, parent, false);

        holder = new ProfileHolder();
        holder.name = (TextView)convertView.findViewById(R.id.nameChar);
        holder.pic = (ImageView)convertView.findViewById(R.id.imageChar);
        holder.rank = (TextView)convertView.findViewById(R.id.ratingNumber);

        convertView.setTag(holder);
    }
    else
    {
        holder = (ProfileHolder)convertView.getTag();
    }

    Profile p = profielen.get(position);
    holder.name.setText(p.getName());
    holder.rank.setText(p.getRating());
    holder.pic.setImageBitmap(p.getThumbNail());

    return convertView;

}

public static class ProfileHolder{
    TextView name;
    ImageView pic;
    TextView rank;
}

public void setImage(int position ,Bitmap bm){
    profielen.get(position).setThumbNail(bm);
    this.notifyDataSetChanged();

}

}

由此改变:

    imgurl =imgCharacter+imgurl;
    ImageLoader imageLoader = getImageLoader(); 
    imageLoader.get(imgurl, new ImageListener() {

                public void onErrorResponse(VolleyError error) {

                }

                public void onResponse(ImageContainer response, boolean arg1) {
                    if (response.getBitmap() != null) {
                        lbadapter.setImage(pos, response.getBitmap());
                        lbadapter.notifyDataSetChanged();

                    } 
                }
            });

Imageloader(Volley)

       imageLoader = new ImageLoader(queue, new ImageLoader.ImageCache() {
        private final LruCache<String, Bitmap> cache = new LruCache<String, Bitmap>           (20);


        @Override
        public Bitmap getBitmap(String url) {
            return cache.get(url);
        }

        @Override
        public void putBitmap(String url, Bitmap bitmap) {
            cache.put(url, bitmap);
        }
    });

0 个答案:

没有答案