多条目加载

来源:互联网 发布:怎么做淘宝货源供应商 编辑:程序博客网 时间:2024/06/05 09:31

在做多条目加载时需要在适配器中多重写两个方法,(getItemViewType(int position))、(getViewTypeCount())

第一个是得到条目视图的类型,返回值是int

       在实际开发中显示哪种条目的类型是根据接口数据中具体的那个字段值来决定的

private int title=0;private int img_left=1;private int img_right=2;private int img_bottom=3;
  public int getItemViewType(int position) {     int a = position%4;    if (a==0){        return title;    }else if(a==1){        return img_left;    }else if(a==2){        return  img_right;    }    return img_bottom;}


第二个是得到视图类型的数量

       也就是这个ListView要展示多少个不同的视图


还有在做优化时,首先要判断是哪一种类型的视图,再根据相关的视图进行优化

  

根据getItemViewType(position)==title进行判断

、、、、、、、、、、、、、、、、、、、、、

用imageLoder设置图片

ImageLoader.getInstance().displayImage(list.get(position).getPicUrl(), vh3.img, new App_Helper().shape());