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.a1.demoyuekao20170328.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
import bean.Userbean;
import utils.ImageUtils;
public class MyAdapter extends BaseAdapter {
private List<Userbean.DataBean> mDatalist;
private Context context;
public MyAdapter(List<Userbean.DataBean> datalist, Context context) {
mDatalist = datalist;
this.context = context;
}
@Override
public int getCount() {
return mDatalist.size();
}
@Override
public Object getItem(int position) {
return mDatalist.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHodler hodler;
if (convertView==null){
convertView = View.inflate(context, R.layout.item,null);
hodler = new ViewHodler();
hodler.mImageView = (ImageView) convertView.findViewById(R.id.imageview);
hodler.text01 = (TextView) convertView.findViewById(R.id.text01);
hodler.text02 = (TextView) convertView.findViewById(R.id.text02);
convertView.setTag(hodler);
}else{
hodler = (ViewHodler) convertView.getTag();
}
ImageLoader.getInstance().displayImage(mDatalist.get(position).getPic_url(),hodler.mImageView, ImageUtils.MyImage(R.mipmap.ic_launcher));
hodler.text01.setText(mDatalist.get(position).getNews_title());
hodler.text02.setText(mDatalist.get(position).getNews_summary());
return convertView;
}
class ViewHodler{
ImageView mImageView;
TextView text01,text02;
}
}