标签:
package com.wt.ada;
import java.util.ArrayList;
import com.lidroid.xutils.BitmapUtils;
import com.wt.top.R;
import com.wt.vo.Data;
import android.content.Context;
import android.opengl.Visibility;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class FragLvAdapter extends BaseAdapter{
private Context con;
private ArrayList<Data> data;
private ViewHolder1 vh1;
private ViewHolder2 vh2;
private BitmapUtils bu;
public FragLvAdapter(Context con, ArrayList<Data> data) {
// TODO Auto-generated constructor stub
this.con=con;
this.data=data;
bu = new BitmapUtils(con);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.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;
}
@SuppressWarnings("unused")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
int size=0;
if (data.get(position).getImage_list()!=null) {
size = data.get(position).getImage_list().size();
}
switch (size) {
case 0:
if (data.get(position).getMiddle_image()!=null) {
convertView=View.inflate(con,R.layout.frag_lv_item1, null);
vh1 = new ViewHolder1();
vh1.title=(TextView) convertView.findViewById(R.id.title);
vh1.image1=(ImageView) convertView.findViewById(R.id.image1);
convertView.setTag(vh1);
vh1.title.setText(data.get(position).getTitle());
vh1.title.setWidth(220);
bu.display(vh1.image1, data.get(position).getMiddle_image().getUrl());
}else {
convertView=View.inflate(con,R.layout.frag_lv_item1, null);
vh1 = new ViewHolder1();
vh1.title=(TextView) convertView.findViewById(R.id.title);
vh1.image1=(ImageView) convertView.findViewById(R.id.image1);
convertView.setTag(vh1);
vh1.title.setText(data.get(position).getTitle());
vh1.image1.setVisibility(View.GONE);
}
break;
case 3:
convertView = null;
if (convertView==null) {
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);
convertView.setTag(vh2);
vh2.title3.setText(data.get(position).getTitle());
bu.display(vh2.image3_1, data.get(position).getImage_list().get(0).getUrl());
bu.display(vh2.image3_2, data.get(position).getImage_list().get(1).getUrl());
bu.display(vh2.image3_3, data.get(position).getImage_list().get(2).getUrl());
}
break;
}
return convertView;
}
class ViewHolder1{
TextView title;
ImageView image1;
}
class ViewHolder2{
TextView title3;
ImageView image3_1;
ImageView image3_2;
ImageView image3_3;
}
}
标签:
原文地址:http://www.cnblogs.com/taogev5/p/5629587.html