标签:ext com public layout switch time settag uil get
//有几个条目类型
@Override
public int getViewTypeCount() {
return 2;
}
//判断怎样分辨每个条目的位置
@Override
public int getItemViewType(int position) {
if(position%2==0){
return 0;
}else{
return 1;
}
}
//得到类型
int type = getItemViewType(position);
/* switch (type){
case 0: //textView
break;
case 1: //
break;
case 2:
break;
}*/
int type = getItemViewType(position);
switch (type) {
case 0:
if (convertView == null) {//不同的布局
convertView = View.inflate(context, R.layout.lv_layout, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(data_list.get(position).getNews_title());
holder.time.setText(data_list.get(position).getNews_summary());
ImageLoader.getInstance().displayImage(data_list.get(position).getPic_url(), holder.img);
break;
case 1:
if (convertView == null) {//不同的布局
convertView = View.inflate(context, R.layout.lv_layout2, null);
holder2 = new ViewHolder2(convertView);
convertView.setTag(holder2);
} else {
holder2 = (ViewHolder2) convertView.getTag();
}
holder2.title_2.setText(data_list.get(position).getNews_title());
break;
}
多条目加载时ListView的优化---复用convertView,减少findViewById的次数
标签:ext com public layout switch time settag uil get
原文地址:http://www.cnblogs.com/Nigeria/p/8006795.html