Bonjour tout le monde j'essai de faire une application composé de plusieurs onglets et plusieurs ListView j'aimerai donc que chaque item de mes Listview lance une ImageView .
J'ai une solution mais ça m'oblige à créer une class pour un Item , j'ai environ 50 items répartis dans les différentes ListView donc je vais pas créer 50 class pour au final faire toujours la même chose ...

Voila mon code :
Le Tab1


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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cbp.st2s;
 
import android.app.Activity;
import android.app.AlertDialog;
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
 
import cbp.st2s.CBPST2SActivity;
 
import cbp.st2s.Tab5;
 
import cbp.st2s.formulaire1;
 
 
import cbp.st2s.R;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
 
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.os.Bundle;
 
 
public class Tab1 extends Activity {
	private ListView maListViewPerso;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.onglet1);
 
 
 
 
 
 
 
                maListViewPerso = (ListView) findViewById(R.id.listView1);
                ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
                HashMap<String, String> map;
                map = new HashMap<String, String>();
                map.put("titre", "1 - STI STL");
                map.put("img", String.valueOf(R.drawable.fleche));
                listItem.add(map);
                map = new HashMap<String, String>();
                map.put("titre", "2 - STI Bio");
                map.put("img", String.valueOf(R.drawable.fleche));
                listItem.add(map);
 
 
                SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.afichageitem,
                       new String[] {"img", "titre" }, new int[] {R.id.fleche, R.id.titre});
                maListViewPerso.setAdapter(mSchedule);
 
 
                maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
              	  public void onItemClick(AdapterView<?> a, View v, int position, long id) {
 
 
 
              	    HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position);
              	    if(map.get("titre").equals("1 - STI STL")) {
              	        startActivity(new Intent(Tab1.this, formulaire1.class));
              	        return;
              	    }
              	    if(map.get("titre").equals("2 - STI Bio")) {
              	        startActivity(new Intent(Tab1.this, formulaire2.class));
              	        return;
              	    }
 
 
 
 
 
 
 
 
            		      Intent intent = new Intent(Intent.ACTION_VIEW);
 
            		      startActivity(intent);
              	  };
                });
                }
 
 
 
      public void onClick(View src) {
    	    Intent i = new Intent(this, CBPST2SActivity.class);
    	    startActivity(i);
    	 };
      }
Lorsque je clique sur "1 - STI STL" ça lance formulaire1 que voila :

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
package cbp.st2s;
 
 
 
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
 
public class formulaire1 extends Activity {
 
	Button button;
	ImageView image;
 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webface);
 
		addListenerOnButton();
 
	}
 
	public void addListenerOnButton() {
 
		image = (ImageView) findViewById(R.id.imageView1);
 
 
 
 
 
 
	}
 
}





Après le TOP serait que je puisse basculer d'un onglet à l'autre en gardant mon ImageView affiché ( exemple: j'ouvre le cours "1 - STI STL" puis je vais sur l'onglet annales et j'ouvre mon sujet puis je reviens sur l'onglet 1 et vois directement la formule qu'il me faut pour mon exercice comme ça je peux naviguer d'un onglet à l'autre en ayant mon cours et mon sujet sans devoir reclicker dessus )