Adapter 有个getView方法,可以使用setTag把查找的view缓存起来方便多次重用
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=minflater.inflate(R.layout.listitem, null);
ViewHolder holder = new ViewHolder();
holder.title=(TextView)convertView.findViewById(R.id.main_title);
holder.second=(TextView)convertView.findViewById(R.id.second_title);
holder.setting=(TextView)convertView.findViewById(R.id.setting_title);
convertView.setTag(holder);
}
ViewHolder holder = (ViewHolder) convertView.getTag();
Map<String, Object> item= (Map<String, Object>)getItem(position);
holder.title.setText((String)item.get(PARAM_MAIN_TITLE));
holder.second.setText((String)item.get(PARAM_SECOND_TITLE));
holder.setting.setText((String)item.get(PARAM_SETTING_TITLE));
return convertView;
}
class ViewHolder{
public TextView title;
public TextView second;
public TextView setting;
}
ViewHolder封装好缓存起来方便多次重用,当需要时可以getTag拿出来
//其他的代码可以直接使用holder.title,holder.second,holder.setting来设置