适配器的数据更新方法notifyDataSetChanged()只有在定义Adapter类时可以调用;
使用ViewHolder优化:
(1)创建Holder:
class Holder{ ImageView p_w_picpathrView; TextView textView; ......... } (2)public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub Holder holder = null; if(convertView==null) { convertView=LayoutInflater.from(context).inflate(resource, null); holder=new Holder(); holder.p_w_picpathView=(ImageView) convertView.findViewById(R.id.p_w_picpathView); holder.textView=(TextView) convertView.findViewById(R.id.textView); convertView.setTag(holder); }else{ holder=(Holder) convertView.getTag(); } holder.p_w_picpathView.setImageResource(p_w_picpath); holder.textView.setText(text) }
(3)View.setTag(Object)和View.getTag():
为View设置附加数据,可以在需要的时候拿来用,在adapter使用是避免了控件的重复实例话,算是一种简单的优化;