package example.com.velezguiatour;

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;

public class LazyAdapter extends BaseAdapter
{
    
    private Activity activity;
    private String[][] data = null;
    private static LayoutInflater inflater = null;
    public ImageLoader imageLoader;
    private int page;
    
    public LazyAdapter(Activity a, String[][] d, int page)
    {
    	this.page = page;
        activity = a;
        data = d;
        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;
        int defaultResource = 0;
        
        if(convertView == null)
        {
            vi = inflater.inflate(R.layout.item, null);
        }
        TextView text=(TextView)vi.findViewById(R.id.text);
      
        ImageView image = (ImageView)vi.findViewById(R.id.image);
        
        switch(position)
        {
        case 0: if (page == 1)defaultResource = R.drawable.juan;
        		if (page == 2)defaultResource = R.drawable.fortaleza;
        		if (page == 3)defaultResource = R.drawable.villa;
        		break;
        case 1: if (page == 1)defaultResource = R.drawable.cerro;
				if (page == 2)defaultResource = R.drawable.beniel;
				if (page == 3)defaultResource = R.drawable.arco;
				break;
        case 2: if (page == 1)defaultResource = R.drawable.maria;
				if (page == 2)defaultResource = R.drawable.cervantes;
				if (page == 3)defaultResource = R.drawable.fernando;
				break;


        default: defaultResource = R.drawable.vacio; break;
        }
        
        
              
        text.setText(data[position][1]);
        imageLoader.DisplayImage(data[position][0], image, defaultResource);
        return vi;
    }
}