我有一个问题,当我滚动我的列表视图,图像似乎继续重新加载自己,它使得列表视图滞后很多。 我能做些什么来防止这种情况发生,我之前在我的listview中做过这件事,而且它没有这样做。毕加索图像重新加载滚动在列表视图
public class PostsAdapter extends BaseAdapter{
public List<PostList> postList;
protected Context context;
public void add(PostList object,int position) {
postList.add(position,object);
}
public PostsAdapter(Context context) {
this.context = context;
postList = new ArrayList<PostList>();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return postList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return postList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView == null){
convertView = LayoutInflater.from(context).inflate(R.layout.posts_list, null);
holder = new ViewHolder();
holder.image = (ImageView)convertView.findViewById(R.id.postImage);
holder.username = (TextView)convertView.findViewById(R.id.postUsername);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
holder.username.setText(postList.get(position).user);
Picasso.with(context).load(postList.get(position).postPicture).into(holder.image);
return convertView;
}
static class ViewHolder{
ImageView image;
TextView username;
}
加上'Picasso.with(上下文).load(postList.get(位置).postPicture).into(架.image);'in you'if(convertView == null){...}'从其他地方移除。 – Rustam 2014-10-22 06:02:35
public void add(PostList对象,int位置){ postList.add(position,object); }这就是为什么你使用 – 2014-10-22 06:04:26
public PostsAdapter(Context context,ArrayList List){ this.context = context; postList = List; }在适配器中使用此缺点 –
2014-10-22 06:05:20