| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 
 | import java.util.ArrayList;
import java.util.HashMap;
import com.wtp.galeriedart.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
 
 
public class voir_photo extends ListActivity{
 
	private ListView malistviewphoto;
 
	/** On déclare toutes les variables dont on aura besoin */
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.voir_photo);
 
      //Récupération de la listview créée dans le fichier voir_photo.xml
        malistviewphoto = (ListView) findViewById(R.id.list);
        //Création de la ArrayList qui nous permettra de remplire la listView
        ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
        //On déclare la HashMap qui contiendra les informations pour un item
        HashMap<String, String> map;
        //Création d'une HashMap pour insérer les informations du premier item de notre listView
        map = new HashMap<String, String>();
        //on insère un élément titre que l'on récupérera dans le textView titre créé dans le fichier affichageitem.xml
        map.put("titrephoto", "Alexandra");
        //on insère un élément description que l'on récupérera dans le textView description créé dans le fichier affichageitem.xml
        map.put("descriptionphoto", "Photos d'art");
        //on insère la référence à l'image (convertit en String car normalement c'est un int) que l'on récupérera dans l'imageView créé dans le fichier affichageitem.xml
        map.put("imgphoto", String.valueOf(R.drawable.van_2b));
        //enfin on ajoute cette hashMap dans la arrayList
        listItem.add(map);
 
      //On refait la manip plusieurs fois avec des données différentes pour former les items de notre ListView
        map = new HashMap<String, String>();
        map.put("titrephoto", "Alexandra");
        map.put("descriptionphoto", "Photos d'art");
        map.put("imgphoto", String.valueOf(R.drawable.van_2b));
        listItem.add(map);
 
      //Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem
        SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.itemsphoto,
               new String[] {"imgphoto", "titrephoto", "descriptionphoto"}, new int[] {R.id.imgphoto, R.id.titrephoto, R.id.descriptionphoto});
 
        //On attribut à notre listView l'adapter que l'on vient de créer
        malistviewphoto.setAdapter(mSchedule);
 
         //Enfin on met un écouteur d'évènement sur notre listView
        malistviewphoto.setOnItemClickListener(new OnItemClickListener(){
        	 	@SuppressWarnings("unchecked")
			public void onItemClick(AdapterView<?> a, View v, int position, long id) {
				//on récupère la HashMap contenant les infos de notre item (titre, description, img)
        		@SuppressWarnings("unused")
				HashMap<String, String> map = (HashMap<String, String>) malistviewphoto.getItemAtPosition(position);
        		CallFunc(position);
        	}
 
				private void CallFunc(int position) {
					Intent intent = null ;
					switch (position){
					case 1:
		        	    intent = new Intent(getBaseContext() , voir_ces_photos.class);
		        	  break;
 
					}
					if(intent != null)
		        	    startActivity(intent); 
				}
         });
 
    }
 
 
} |