推荐:http://ic.snssdk.com/2/article/v25/stream/?count=20&min_behot_time=1504621638&bd_latitude=4.9E-324&bd_longitude=4.9E-324&bd_loc_time=1504622133&loc_mode=5&loc_time=1504564532&latitude=35.00125&longitude=113.56358166666665&city=%E7%84%A6%E4%BD%9C&lac=34197&cid=23201&iid=14534335953&device_id=38818211465&ac=wifi&channel=baidu&aid=13&app_name=news_article&version_code=460&device_platform=android&device_type=SM-E7000&os_api=19&os_version=4.4.2&uuid=357698010742401&openudid=74f06d2f9d8c9664
一共是四种样式的条目:
判断has_video不为null,并且为true....视频的条目,获取...large_image_list(非空判断)中的第一张图片显示
否则,判断has_image不为null,并且为true,,,获取image_list(非空)...如果>=3,显示三张图片的条目,,,否则条目为右边一张图片,左边标题
//样式总数不能>=样式总数
否则就是只有标题的形式
private int num1=0;//四种样式
private int num2=1;
private int num3=2;
private int num4=3;
@Override
public int getViewTypeCount() {
return 4;
}
//试图
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int itemViewType = getItemViewType( position );
if(itemViewType==num1){
Viewholder1 holder;
if(convertView==null){
convertView=View.inflate(context, R.layout.item1,null );
holder=new Viewholder1();
holder.img=convertView.findViewById( R.id.img1 );
holder.title=convertView.findViewById( R.id.title_1_1_tv );
convertView.setTag( holder);
}else {
holder=(Viewholder1) convertView.getTag();
}
holder.title.setText( listarray.get( position ).getTitle() );
ImageLoader.getInstance().displayImage(listarray.get(position).getLarge_image_list().get(0).getUrl(),holder.img,options);
}else if(itemViewType==num2){
Viewholder2 holder;
if(convertView==null){
convertView=View.inflate(context, R.layout.item2,null );
holder=new Viewholder2();
holder.img1=convertView.findViewById( R.id.img2_1 );
holder.img2=convertView.findViewById( R.id.img2_2 );
holder.img3=convertView.findViewById( R.id.img2_3);
holder.title=convertView.findViewById( R.id.title_2_1 );
convertView.setTag( holder);
}else {
holder=(Viewholder2) convertView.getTag();
}
String url1 = listarray.get( position ).getImage_list().get( 0 ).getUrl_list().get( 0 ).getUrl();
String url2 = listarray.get( position ).getImage_list().get( 0 ).getUrl_list().get( 1 ).getUrl();
String url3 = listarray.get( position ).getImage_list().get( 0 ).getUrl_list().get( 2 ).getUrl();
ImageLoader.getInstance().displayImage(url1,holder.img1,options );
ImageLoader.getInstance().displayImage(url2,holder.img2,options );
ImageLoader.getInstance().displayImage(url3,holder.img3,options );
holder.title.setText( listarray.get( position ).getTitle() );
}else if(itemViewType==num3){
Viewholder3 holder;
if(convertView==null){
convertView=View.inflate(context, R.layout.item03,null );
holder=new Viewholder3();
holder.img=convertView.findViewById( R.id.img_3_1 );
holder.title=convertView.findViewById( R.id.title_v3 );
convertView.setTag( holder);
}else {
holder=(Viewholder3) convertView.getTag();
}
String url1 = listarray.get( position ).getImage_list().get( 0 ).getUrl_list().get( 0 ).getUrl();
ImageLoader.getInstance().displayImage(url1,holder.img,options );
String title = listarray.get( position ).getTitle();
holder.title.setText( title );
}else if(itemViewType==num4){
Viewholder4 holder;
if(convertView==null){
convertView=View.inflate(context, R.layout.item4,null );
holder=new Viewholder4();
holder.title=convertView.findViewById( R.id.title_v4 );
convertView.setTag( holder);
}else {
holder=(Viewholder4) convertView.getTag();
}
holder.title.setText(listarray.get( position ).getTitle());
}
return convertView;
//四种方式
@Override
public int getItemViewType(int position) {
//多条目加载条件
boolean isvideo = InstanceTool.isInsance(listarray.get( position ), "has_video");
if(isvideo){
boolean has_video = listarray.get( position ).isHas_video();
if(has_video){
List
large_image_list = listarray.get( position ).getLarge_image_list();
if(large_image_list!=null){
return num1;
}else{
boolean has_image = InstanceTool.isInsance(listarray.get(position), "has_image");
if(has_image){
List image_list = listarray.get( position ).getImage_list();
if(image_list!=null){
if(image_list.size()>=3){
return num2;
}else{
return num3;
}
}else{
return num4;
}
}else{
return num4;
}
}
}else{
boolean has_image = InstanceTool.isInsance(listarray.get(position), "has_image");
if(has_image){
List image_list = listarray.get( position ).getImage_list();
if(image_list!=null){
if(image_list.size()>=3){
return num2;
}else{
return num3;
}
}else{
return num4;
}
}else{
return num4;
}
}
}else{
boolean has_image = InstanceTool.isInsance(listarray.get(position), "has_image");
if(has_image){
List image_list = listarray.get( position ).getImage_list();
if(image_list!=null){
if(image_list.size()>=3){
return num2;
}else{
return num3;
}
}else{
return num4;
}
}else{
return num4;
}
}
}