标签:
package com.wt.ada;
import java.util.ArrayList;
import com.lidroid.xutils.BitmapUtils;
import com.wt.top.R;
import com.wt.vo.Collect;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class CollectAdapter extends BaseAdapter {
private Context con;
private ArrayList<Collect> list;
private ViewHolder vh;
private ViewHolder2 vh2;
private BitmapUtils bu;
public CollectAdapter(Context con, ArrayList<Collect> list) {
// TODO Auto-generated constructor stub
this.con = con;
this.list = list;
bu = new BitmapUtils(con);
}
@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 int getItemViewType(int position) {
// TODO Auto-generated method stub
return list.get(position).getType();
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 3;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
int type = getItemViewType(position);
if (convertView == null) {
switch (type) {
case 1:
convertView = View.inflate(con, R.layout.frag_lv_item1, null);
vh = new ViewHolder();
vh.title = (TextView) convertView.findViewById(R.id.title);
vh.image1 = (ImageView) convertView.findViewById(R.id.image1);
vh.jia = (ImageView) convertView.findViewById(R.id.jia);
vh.title.setText(list.get(position).getTitle());
vh.image1.setVisibility(View.GONE);
vh.jia.setVisibility(View.GONE);
convertView.setTag(convertView);
break;
case 2:
convertView = View.inflate(con, R.layout.frag_lv_item1, null);
vh = new ViewHolder();
vh.title = (TextView) convertView.findViewById(R.id.title);
vh.image1 = (ImageView) convertView.findViewById(R.id.image1);
vh.jia = (ImageView) convertView.findViewById(R.id.jia);
vh.title.setText(list.get(position).getTitle());
vh.title.setWidth(249);
bu.display(vh.image1, list.get(position).getUrl());
vh.jia.setVisibility(View.GONE);
convertView.setTag(convertView);
break;
case 3:
convertView = View.inflate(con, R.layout.frag_lv_item3, null);
vh2 = new ViewHolder2();
vh2.title3 = (TextView) convertView.findViewById(R.id.title3);
vh2.image3_1 = (ImageView) convertView
.findViewById(R.id.image3_1);
vh2.image3_2 = (ImageView) convertView
.findViewById(R.id.image3_2);
vh2.image3_3 = (ImageView) convertView
.findViewById(R.id.image3_3);
vh2.jia3 = (ImageView) convertView.findViewById(R.id.jia3);
vh2.title3.setText(list.get(position).getTitle());
bu.display(vh2.image3_1, list.get(position).getImage1());
bu.display(vh2.image3_2, list.get(position).getImage2());
bu.display(vh2.image3_3, list.get(position).getImage3());
vh2.jia3.setVisibility(View.GONE);
convertView.setTag(convertView);
break;
}
} else {
switch (type) {
case 1:
vh = (ViewHolder) convertView.getTag();
break;
case 2:
vh = (ViewHolder) convertView.getTag();
break;
case 3:
vh2 = (ViewHolder2) convertView.getTag();
break;
default:
break;
}
}
return convertView;
}
class ViewHolder {
TextView title;
ImageView image1;
ImageView jia;
}
class ViewHolder2 {
TextView title3;
ImageView image3_1;
ImageView image3_2;
ImageView image3_3;
ImageView jia3;
}
}
标签:
原文地址:http://www.cnblogs.com/taogev5/p/5631118.html