[android]代码库
/**
*一个XML实现Listview多条目加载
*/
package com.example.listview;
import java.util.ArrayList;
import java.util.List;
import com.example.bean.Data;
import com.example.bean.Iarge_image_list;
import com.example.bean.Image_list;
import com.example.bean.Middle_image;
import com.lidroid.xutils.BitmapUtils;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Myadapter extends BaseAdapter {
private Context context;
private List<Data> list;
public Myadapter(Context context, List<Data> list) {
super();
this.context = context;
this.list = list;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder1 v1=null;
if(convertView==null){
convertView=View.inflate(context, R.layout.item, null);
v1=new ViewHolder1();
v1.line1=(LinearLayout) convertView.findViewById(R.id.line1);
v1.title1=(TextView) convertView.findViewById(R.id.title1);
v1.imageView1=(ImageView) convertView.findViewById(R.id.line1_image1);
v1.imageView2=(ImageView) convertView.findViewById(R.id.line1_image2);
v1.imageView3=(ImageView) convertView.findViewById(R.id.line1_image3);
v1.line2=(LinearLayout) convertView.findViewById(R.id.line2);
v1.title2=(TextView) convertView.findViewById(R.id.title2);
v1.line2_image=(ImageView) convertView.findViewById(R.id.line2_image);
v1.line3=(LinearLayout) convertView.findViewById(R.id.line3);
v1.title3=(TextView) convertView.findViewById(R.id.title3);
v1.line3_image=(ImageView) convertView.findViewById(R.id.line3_image);
v1.line4=(LinearLayout) convertView.findViewById(R.id.line4);
v1.title4=(TextView) convertView.findViewById(R.id.title4);
convertView.setTag(v1);
}else{
v1=(ViewHolder1) convertView.getTag();
}
List<Image_list> Image_list=new ArrayList<Image_list>();
List<Iarge_image_list> Iarge_image_list=new ArrayList<Iarge_image_list>();
List<String> Middle_image=new ArrayList<String>();
Image_list.addAll(list.get(position).image_list);
Iarge_image_list.addAll(list.get(position).large_image_list);
Middle_image.add(list.get(position).middle_image.url);
String title=list.get(position).title;
if(Iarge_image_list.size()>0){
v1.line3.setVisibility(View.VISIBLE);
v1.line1.setVisibility(View.GONE);
v1.line2.setVisibility(View.GONE);
v1.line4.setVisibility(View.GONE);
new BitmapUtils(context).display(v1.line3_image,Iarge_image_list.get(0).url);
v1.title3.setText(title);
}else
if(Image_list.size()>0){
v1.line1.setVisibility(View.VISIBLE);
v1.line3.setVisibility(View.GONE);
v1.line2.setVisibility(View.GONE);
v1.line4.setVisibility(View.GONE);
new BitmapUtils(context).display(v1.imageView1,Image_list.get(0).url);
new BitmapUtils(context).display(v1.imageView2,Image_list.get(1).url);
new BitmapUtils(context).display(v1.imageView3,Image_list.get(2).url);
v1.title1.setText(title);
}else
if(Middle_image.size()>0){
v1.line2.setVisibility(View.VISIBLE);
v1.line3.setVisibility(View.GONE);
v1.line1.setVisibility(View.GONE);
v1.line4.setVisibility(View.GONE);
new BitmapUtils(context).display(v1.line2_image,Middle_image.get(0));
v1.title2.setText(title);
}else{
v1.line4.setVisibility(View.VISIBLE);
v1.line2.setVisibility(View.GONE);
v1.line3.setVisibility(View.GONE);
v1.line1.setVisibility(View.GONE);
v1.title4.setText(title);
}
return convertView;
}
class ViewHolder1{
LinearLayout line1,line2,line3,line4;
TextView title1,title2,title3,title4;
ImageView imageView1,imageView2,imageView3,line2_image,line3_image;
}
}