package com.bawei.week3.adapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bawei.week3.R;
import com.bawei.week3.bean.One;
import com.bawei.week3.bean.Two;
import com.bumptech.glide.Glide;
import java.util.List;
/**
-
@Author:南方小酒馆°
-
@E-mail:
-
@Date:2019/3/2 9:10
-
@Description:描述信息
*/
public class PullAdapter extends BaseAdapter {private List list;
private Context context;public PullAdapter(List list, Context context) {
this.list = list;
this.context = context;
}@Override
public int getCount() {
return list.size();
}@Override
public Object getItem(int position) {
return null;
}@Override
public long getItemId(int position) {
return 0;
}@Override
public View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
switch (type){
case 0:
ViewHolder1 holder1 = null;
if (convertViewnull){
convertView = View.inflate(context, R.layout.item_pull,null);
holder1 = new ViewHolder1();
holder1.textView1 = convertView.findViewById(R.id.tv1);
holder1.imageView1 = convertView.findViewById(R.id.img1);
convertView.setTag(holder1);
}else {
holder1 = (ViewHolder1) convertView.getTag();
}
One one = list.get(position);
holder1.textView1.setText(one.getCommodityName());
Glide.with(context).load(one.getMasterPic()).into(holder1.imageView1);
break;
case 1:
ViewHolder2 holder2 = null;
if (convertViewnull){
convertView = View.inflate(context, R.layout.item2,null);
holder2 = new ViewHolder2();
holder2.textView2 = convertView.findViewById(R.id.tv2);
holder2.imageView2 = convertView.findViewById(R.id.img2);
convertView.setTag(holder2);
}else {
holder2 = (ViewHolder2) convertView.getTag();
}
One one2 = list.get(position);
holder2.textView2.setText(one2.getCommodityName());
Glide.with(context).load(one2.getMasterPic()).into(holder2.imageView2);
break;
case 2:
ViewHolder3 holder3 = null;
if (convertView==null){
convertView = View.inflate(context, R.layout.item3,null);
holder3 = new ViewHolder3();
holder3.textView3 = convertView.findViewById(R.id.tv3);
convertView.setTag(holder3);
}else {
holder3 = (ViewHolder3) convertView.getTag();
}
One one3 = list.get(position);
holder3.textView3.setText(one3.getCommodityName());
break;
}
return convertView;
}
class ViewHolder1{
private TextView textView1;
private ImageView imageView1;
}
class ViewHolder2{
private TextView textView2;
private ImageView imageView2;
}
class ViewHolder3{
private TextView textView3;
private ImageView imageView3;
}@Override
public int getViewTypeCount() {
return 3;
}@Override
public int getItemViewType(int position) {
return position % 3;
}
}