package com.bwie.week_two.apdater;
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.bwie.week_two.MainActivity;
import com.bwie.week_two.R;
import com.bwie.week_two.bean.Uibean;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
public class Myapdater extends BaseAdapter {
Context context;
List<Uibean.ResultBean.DataBean> list;
public Myapdater(Context context, List<Uibean.ResultBean.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 View getView(int position, View convertView, ViewGroup parent) {
int itemViewType = getItemViewType(position);
switch (itemViewType){
case 1:
ViewHoderone hoderone = null;
if(convertView==null) {
convertView = View.inflate(context, R.layout.item1, null);
hoderone = new ViewHoderone();
hoderone.title=convertView.findViewById(R.id.titles);
hoderone.image=convertView.findViewById(R.id.images_view);
convertView.setTag(hoderone);
}else{
hoderone= (ViewHoderone) convertView.getTag();
}
hoderone.title.setText(list.get(position).getTitle());
ImageLoader.getInstance().displayImage(list.get(position).getUrl(),hoderone.image);
break;
case 2:
ViewHodertwo hodertwo = null;
if(convertView==null) {
convertView = View.inflate(context, R.layout.item2, null);
hodertwo = new ViewHodertwo();
hodertwo.image_01=convertView.findViewById(R.id.image_view1);
hodertwo.image_02=convertView.findViewById(R.id.image_view2);
hodertwo.image_03=convertView.findViewById(R.id.image_view3);
convertView.setTag(hodertwo);
}else{
hodertwo= (ViewHodertwo) convertView.getTag();
}
ImageLoader.getInstance().displayImage(list.get(position).getThumbnail_pic_s(),hodertwo.image_01);
ImageLoader.getInstance().displayImage(list.get(position).getThumbnail_pic_s02(),hodertwo.image_02);
ImageLoader.getInstance().displayImage(list.get(position).getThumbnail_pic_s03(),hodertwo.image_03);
break;
}
return convertView;
}
@Override
public int getViewTypeCount() {
return 3;
}
@Override
public int getItemViewType(int position) {
String images = list.get(position).getThumbnail_pic_s();
if(images==null&&images!=null){
return 1;
}else {
return 2;
}
// return super.getItemViewType(position);
}
class ViewHoderone{
TextView title;
ImageView image;
}
class ViewHodertwo{
ImageView image_01;
ImageView image_02;
ImageView image_03;
}
}