public class MyAdapter extends BaseAdapter {
private Context context;
private List<NewsBean.DataBean> list;
public MyAdapter(Context context, List<NewsBean.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) {
ViewHolder holder;
if (convertView==null){
convertView = View.inflate(context, R.layout.list_layout,null);
holder = new ViewHolder();
holder.img_view = convertView.findViewById(R.id.img_view);
holder.news_title = convertView.findViewById(R.id.news_title);
holder.news_summary = convertView.findViewById(R.id.news_summary);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
ImageLoader.getInstance().displayImage(list.get(position).getPic_url(),holder.img_view);
holder.news_title.setText(list.get(position).getNews_title());
holder.news_summary.setText(list.get(position).getNews_summary());
return convertView;
}
class ViewHolder{
private ImageView img_view;
private TextView news_title,news_summary;
}
}