ListView中convertView的重用

在自定义的Adapter中,getView()方法里:

xxxx    getView(){

ViewHolder holder = null;

if(convertView==null){

     convertView = inflater.inflate(R.layout.xxx,null);

     holder = new ViewHolder();

     holder.tv = (TextView)convertView.findViewById(R.id.xxx);

     ......

    convertView.setTag(holder);

}else{

   holder = (ViewHolder)convertView.getTag();

}

holder.tv.setText(items.get(position).toString());

......

}

//定义一个内部类

ViewHolder{

  TextView tv;

  ......

}

 

PS:也许有许多的错处,请斧正,共同进步,谢谢!


原文链接: http://blog.csdn.net/bys0201/article/details/7244692

你可能感兴趣的:(ListView中convertView的重用)