package com.example.day8_2;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.CircleBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import java.util.ArrayList;
import java.util.List;
public class Adapter extends BaseAdapter {
private List<Bean.DataBean> list;
private Context context;
public Adapter(Context context) {
this.context = context;
list = new ArrayList<>();
}
public void setList(List<Bean.DataBean>list){
this.list = list;
notifyDataSetChanged();
}
@Override
public int getCount() {
return list.size();
}
@Override
public Bean.DataBean 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) {
ViewHolder holder;
if(convertView == null){
convertView = LayoutInflater.from(context).inflate(R.layout.item,parent,false);
holder = new ViewHolder();
holder.textView1 = convertView.findViewById(R.id.text2);
holder.textView2 = convertView.findViewById(R.id.text);
holder.view = convertView.findViewById(R.id.image);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.textView1.setText(list.get(position).getNews_summary());
holder.textView2.setText(list.get(position).getNews_title());
//Util.bitmap(list.get(position).getPic_url(),holder.view);
DisplayImageOptions options = new DisplayImageOptions.Builder()
//配置色彩模式
.bitmapConfig(Bitmap.Config.RGB_565)
//配置是否缓存
.cacheInMemory(true)
.cacheOnDisk(true)
//配置默认显示
.showImageOnLoading(R.mipmap.ic_launcher)
.showImageOnFail(R.mipmap.ic_launcher)
.showImageForEmptyUri(R.mipmap.ic_launcher)
//配置图片如何缩放
.imageScaleType(ImageScaleType.EXACTLY)
.displayer(new CircleBitmapDisplayer())
.build();
//加载图片
ImageLoader
.getInstance()
.displayImage(getItem(position).getPic_url(),holder.view,options);
return convertView;
}
class ViewHolder{
TextView textView1,textView2;
ImageView view;
}
}