package com.example.primo;

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

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity implements OnItemClickListener {
	
	private ListView listView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		listView = (ListView) findViewById(R.id.listView1);
		LesDuos lesDuos = new LesDuos();
		
		ArrayList<HashMap<String, String>> liste = lesDuos.donneListe();
		SimpleAdapter adapter = new SimpleAdapter(this, liste, R.layout.liste_duo,
				new String[] { "garcon", "fille", "epoque" },
				new int[] {R.id.textView1, R.id.textView2, R.id.textView3 });
	
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {		
		Toast.makeText(MainActivity.this, "cliqué sur "+
				((HashMap<String, String>) listView.getAdapter().getItem(position)).get("garcon"),
				Toast.LENGTH_SHORT).show();
	}
}
