package com.example.jdmall;

import android.app.Person;
import android.content.Context;
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 java.util.ArrayList;
import java.util.List;

public class JDAdapter extends BaseAdapter {
    private List<JDMechandises> pdata=new ArrayList<JDMechandises>();
    private Context context;
    public JDAdapter(List<JDMechandises> pdata, Context context){
        this.pdata=pdata;
        this.context=context;
    }
    @Override
    public int getCount(){
        return pdata.size();
    }

    @Override
    public Object getItem(int i) {
        return pdata.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    static class ViewHolder{
        public ImageView peopleimg;
        public TextView peoplename;
        public TextView peonumber;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if(convertView==null){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.mechandiseitem,viewGroup,false);
            holder.peopleimg=(ImageView) convertView.findViewById(R.id.peos_img);
            holder.peoplename=(TextView) convertView.findViewById(R.id.peos_name);
            holder.peonumber=(TextView) convertView.findViewById(R.id.peos_number);
            convertView.setTag(holder);
        }else{
            holder=(ViewHolder) convertView.getTag();
        }
        holder.peopleimg.setImageResource(pdata.get(i).getImg());
        holder.peoplename.setText(pdata.get(i).getName());
        holder.peonumber.setText(pdata.get(i).getTelnumber());
        return convertView;
    }

}
