package hunnu.sj.raise_money;

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 java.util.ArrayList;
//信息的适配器
public class NewsAdapter extends BaseAdapter {
    private ArrayList<News> list;
    private Context context;
    public NewsAdapter(Context context,ArrayList<News> 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) {
        View view = null;
        if(convertView != null){
            view  = convertView;
        }else{
            view = View.inflate(context,R.layout.info_item_layout,null);
        }
        ImageView item_icon = (ImageView) view.findViewById(R.id.item_head_icon);
        TextView item_title = (TextView) view.findViewById(R.id.item_info_title);
        TextView item_des = (TextView) view.findViewById(R.id.item_info_des);
        News news = list.get(position);
        item_icon.setImageDrawable(news.getHead_icon());
        item_title.setText(news.getTitle());
        item_des.setText(news.getDes());

        return view;
    }
}