package com.zhongshu.maintenanceexpert.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongshu.maintenanceexpert.R;
import com.zhongshu.maintenanceexpert.bean.HomeLvBean;

import java.util.List;

/**
 * Created by a on 2016/12/28.
 */

public class HomeLvAdapter extends BaseAdapter {

    private List<HomeLvBean> list;

    public HomeLvAdapter(List<HomeLvBean> list) {
        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 = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_position,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.home_lv_address.setText(list.get(position).getAddress());
        holder.home_lv_defect.setText(list.get(position).getDefect());
        holder.home_lv_grade.setText(list.get(position).getGrade());
        holder.home_lv_distance.setText(list.get(position).getDistance() + "m");
        holder.home_lv_date.setText(list.get(position).getDate());
        return convertView;
    }
    class ViewHolder{
        TextView home_lv_address,home_lv_defect,home_lv_grade,home_lv_distance,home_lv_date;

        public ViewHolder(View convertView) {
            home_lv_address = (TextView) convertView.findViewById(R.id.home_lv_address);
            home_lv_defect = (TextView) convertView.findViewById(R.id.home_lv_defect);
            home_lv_grade = (TextView) convertView.findViewById(R.id.home_lv_grade);
            home_lv_distance = (TextView) convertView.findViewById(R.id.home_lv_distance);
            home_lv_date = (TextView) convertView.findViewById(R.id.home_lv_date);
        }
    }
}
