/*
*多条目加载
*/
//只有文本
private final int ONLY_TITLE=0;
//有图片且在右边
private final int ONLY_IMAGE_RIGHT=1;
private final DisplayImageOptions options;
//返回视图类型的个数
@Override
public int getViewTypeCount() {
return 2;
}
//根据条目的下标,得到此条目到底应该是显示哪种类型视图,返回的是int
@Override
public int getItemViewType(int position) {
//根据数据来判断,显示哪种类型
List<String> picurls=results.get(position).getImages();
if(picurls==null){
return ONLY_TITLE;//返回文本类型
}else if(picurls!=null && picurls.size()==1){//集合长度是1
return ONLY_IMAGE_RIGHT;//返回图片类型
}else{
return ONLY_TITLE;//返回文本类型
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//判断条目的类型
int type=getItemViewType(position);
Log.d("zzz","type:"+type+" position:"+position);
if(type==ONLY_TITLE){
ViewHolderTitle holderTitle;
if(convertView==null){
holderTitle=new ViewHolderTitle();
convertView=View.inflate(context,R.layout.item_title,null);
holderTitle.tvTitle=(TextView) convertView.findViewById(R.id.tvtitle);
convertView.setTag(holderTitle);
}else{
holderTitle=(ViewHolderTitle) convertView.getTag();
}
//显示数据
holderTitle.tvTitle.setText(results.get(position).getDesc());
return convertView;
}else if(type==ONLY_IMAGE_RIGHT){
ViewHolderImage holderImage;
if(convertView==null){
holderImage=new ViewHolderImage();
convertView=View.inflate(context,R.layout.item_image,null);
holderImage.tvTitle=(TextView) convertView.findViewById(R.id.tvtitle);
holderImage.img=(ImageView) convertView.findViewById(R.id.img);
convertView.setTag(holderImage);
}else{
holderImage=(ViewHolderImage) convertView.getTag();
}
//显示数据
holderImage.tvTitle.setText(results.get(position).getDesc());
//显示图片
ImageLoader.getInstance().displayImage(results.get(position).getImages().get(0),holderImage.img,options);
Log.d("zzz","type:"+type+" "+results.get(position).getImages().get(0));
return convertView;
}else{
}
return convertView;
}
class ViewHolderTitle{
TextView tvTitle;
}
class ViewHolderImage{
ImageView img;
TextView tvTitle;
本文链接:https://my.lmcjl.com/post/1402.html
4 评论