package 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.example.w.lianxi43.MainActivity;
import com.example.w.lianxi43.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.ArrayList;
import java.util.List;
import bean.UserBean;
public class ChannelOneAdapter extends BaseAdapter {
private static final int ITEM_ONT =1;
private static final int ITEM_TWO =2 ;
private Context context;
private List<UserBean.DataBean> list;
private viewHolder1 holder1;
public ChannelOneAdapter(Context context, List<UserBean.DataBean> list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
String img = list.get(position).getCdn_img();
if (img == null) {
return ITEM_ONT;
} else {
return ITEM_TWO;
}
}
@Override
public int getViewTypeCount() {
return 3;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
switch (type){
case ITEM_ONT:
viewHolder1 holder1=null;
if (convertView == null) {
convertView = View.inflate(context, R.layout.item_layout1, null);
holder1 = new viewHolder1();
holder1.image = convertView.findViewById(R.id.image_view);
holder1.name = convertView.findViewById(R.id.text_name);
holder1.type = convertView.findViewById(R.id.text_type);
convertView.setTag(holder1);
} else {
holder1= (viewHolder1) convertView.getTag();
}
holder1.type.setText(list.get(position).getType());
holder1.name.setText(list.get(position).getName());
ImageLoader.getInstance().displayImage(list.get(position).getProfile_image(),holder1.image);
break;
case ITEM_TWO:
viewHolder2 holder2=null;
if (convertView == null) {
convertView = View.inflate(context, R.layout.item_layout2, null);
holder2 = new viewHolder2();
holder2.name = convertView.findViewById(R.id.text_name2);
holder2.type = convertView.findViewById(R.id.text_type2);
convertView.setTag(holder2);
} else {
holder2= (viewHolder2) convertView.getTag();
}
holder2.type.setText(list.get(position).getType());
holder2.name.setText(list.get(position).getName());
break;
}
return convertView;
}
class viewHolder{
TextView type;
TextView name;
}
class viewHolder1 extends viewHolder{
ImageView image;
}
class viewHolder2 extends viewHolder{
}
}
MyAdapter
最新推荐文章于 2018-11-22 21:07:22 发布