Bonjour,
je vous écrit car je suis en train de développer une appli pour Android et j'ai un problème avec les Adapter. J'affiche sur une activité une liste contenant des infos sur un cinéma. J'ai donc créé une classe ListCinemaAdapter qui contient tous ces éléments, j'ai également utilisé deux fichiers xml pour l'affichage.
Le problème est que je ne sais pas comment accéder correctement à un élément précis de cette liste pour l'afficher. Voici mon code :

cinemaActivity.java :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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
public class CinemaActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cinemas);
 
        addOnClickListener();
 
        ContainerDataCinema.setURL("xxxx");
        ArrayList<cinema> cinemas = ContainerDataCinema.getCinemas();
        for (cinema cinema : cinemas) {
			Log.e("cinemaPlayer",cinema.toString());
		}
        ListCinemaAdapter lfa = new ListCinemaAdapter(this, cinemas);
        ((ListView)findViewById(R.id.listCinema)).setAdapter(lfa);
        //PS  : la liste est correctement affichée.
    }
    private void addOnClickListener() {
		  ListView listedepense = (ListView) findViewById(R.id.listCinema); 
 
	      listedepense.setOnItemClickListener(new OnItemClickListener() {
	    	    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
	    	        String cinema_name = ((TextView)findViewById(R.id.cinema_name)).getText().toString();
	    	        Toast.makeText(getApplicationContext(), "cinema: "+cinema_name+" Parent:"+parent.getSelectedItemId()+" position:"+position+" id:"+id, 5).show();
 
	    	    }
	      });
}
}
j'ajoute aussi les xml pour que vous imaginiez ce qui est affiché, et donc ce que contient la classe cinema, ListCinemaAdapter contenant plusieurs cinémas :
cinema_view.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal">
  <TextView 
  		android:id="@+id/cinema_name"  
  		android:layout_width="wrap_content" 
  		android:layout_height="wrap_content"
  		android:layout_marginRight="10px"
 	/>
 
  <LinearLayout 
	  android:layout_width="wrap_content"
	  android:layout_height="wrap_content"
  	  android:orientation="vertical"
  >
  	<TextView 
  		android:id="@+id/address"  
  		android:layout_width="wrap_content" 
  		android:layout_height="wrap_content"/>
  	<TextView 
  		android:id="@+id/phone"  
  		android:layout_width="wrap_content" 
  		android:layout_height="wrap_content"/>
  	<TextView 
  		android:id="@+id/mail"  
  		android:layout_width="wrap_content" 
  		android:layout_height="wrap_content"/>
  	 <TextView 
  		android:id="@+id/hours" 
  		android:layout_width="wrap_content" 
  		android:layout_height="wrap_content"
	/>
  </LinearLayout>
</LinearLayout>
activity_cinema.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 
	<ImageView android:src="@drawable/logo" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
	<ListView android:id="@+id/listCinema" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView>
</LinearLayout>
Après compilation, la liste s'afficher et un toast contenant les informations voulues apparait quand je clique sur un élément de la liste. La variable position est correcte, elle affiche 0 si j'appuie sur la première case, 1 si c'est la deuxième, etc...
En revanche cinema_name a toujours un temps de retard : pour les 3 premières cases il m'affiche le nom du premier cinema (alors qu'elles contiennent 3 noms de ciné différents), puis la 4 ème case donne le nom du deuxième, la 5ème aussi et le retard se répercute jusqu'au bout de la liste.
Il y aurait-il un moyen de régler se problème ?
Merci.