package com.example.patrice.rerservation01;


import android.app.Activity;
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 com.example.patrice.rerservation01.imageutils.ImageLoader;

import java.util.ArrayList;
import java.util.HashMap;

public class Listview_Adapter extends BaseAdapter
{
    
    private Activity activity;
    private String[] data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader;

    private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String, String>>();

    public Listview_Adapter(Activity a, String[] d, ArrayList<HashMap<String, String>> list)
    {
        activity = a;
        data=d;
        MyArr = list;

        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.row_listview_item, null);

        TextView text=(TextView)vi.findViewById(R.id.text);;
        ImageView image=(ImageView)vi.findViewById(R.id.image);

        //text.setText("item "+position);

        text.setText( MyArr.get(position).get("nom") );

        imageLoader.DisplayImage(data[position], image);
        return vi;
    }
}