Bonjour,

J'utilise l'objet viewflow (https://github.com/pakerfeldt/android-viewflow) dans mon projet, ce qui permet de scroller horizontalement pour ceux qui ne connaisse pas.

Voici mon code :

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
public class DiffVF extends Activity implements OnItemClickListener {
 
	DBAdapter db;
	private ViewFlow viewFlow;
	private ListView listview;
	int tailleCursor;
	int i = 0;
	int[] listCh;
	TextView date;
	int v;
 
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.title_layout);
        Intent thisIntent = getIntent();
        listCh = thisIntent.getExtras().getIntArray("list_id");
        db = new DBAdapter(this);
        db.open();
 
		viewFlow = (ViewFlow) findViewById(R.id.viewflow);
        DiffAdapter adapter = new DiffAdapter(this, listCh);
        viewFlow.setAdapter(adapter);
		TitleFlowIndicator indicator = (TitleFlowIndicator) findViewById(R.id.viewflowindic);
		indicator.setTitleProvider(adapter);
		viewFlow.setFlowIndicator(indicator);
 
		listview = (ListView) findViewById(R.id.listView1);
		listview.setOnItemClickListener(this);
    }
 
    public void onItemClick(AdapterView<?> a, View v, int position, long id) {
		Cursor c =  (Cursor) listview.getItemAtPosition(position);
    	Intent intent = new Intent(getBaseContext(), BC.class);
    	intent.putExtra("id", c.getInt(0));
    	intent.putExtra("id_ch", c.getInt(12));
    	startActivity(intent); 
    }
Avec le DiffAdapter :

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
public class DiffAdapter extends BaseAdapter implements TitleProvider {
 
		DBAdapter db;
		int i = 0;
		int j = 0;
		int[] listCh;
		int nb_chauf;
        int VIEW_MAX_COUNT;
        ArrayList<String> namesList = new ArrayList<String>();
        ArrayList<SimpleCursorAdapter> adapList = new ArrayList<SimpleCursorAdapter>();
        String[] names;
        SimpleCursorAdapter[] adap;
 
    private LayoutInflater mInflater;
 
    public DiffAdapter(Context context, int[] ch) {
//    	toIntArray(ch);
    	listCh = ch;
    	nb_chauf = listCh.length;
    	VIEW_MAX_COUNT = nb_chauf;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //-----Ouverture BDD
        db = new DBAdapter(context);
        db.open();
        //-----
        //-----Recuperation liste des ch
        while(i < nb_chauf)
        {
        	Cursor c = db.recupererCh(String.valueOf(listCh[i]));
        	c.moveToFirst();
        	namesList.add(c.getString(1)+"  "+c.getString(2));
        	i++;
        }
        names = namesList.toArray(new String[namesList.size()]);
        //-----
        //-----Recuperation liste de BC
        while(j < nb_chauf)
        {
	        Cursor c = db.recupererInfoBC(listCh[j]);
	    	c.moveToFirst();
	    	adapList.add (new SimpleCursorAdapter(context, R.layout.recup_listinfobc, c,
	    	    	new String[]{"numero_bc", "heure_depart", "ville_depart"},
	    	    	new int[]{R.id.textNumeroBC, R.id.textHeureDepart, R.id.textVilleDepart} ));
	    	j++;
        }
        adap = adapList.toArray(new SimpleCursorAdapter[adapList.size()]);
    }
 
    @Override
    public int getItemViewType(int position) {
        return position;
    }
 
    @Override
    public int getViewTypeCount() {
        return VIEW_MAX_COUNT;
    }
 
 
    public int getCount() {
        return VIEW_MAX_COUNT;
    }
 
 
    public Object getItem(int position) {
        return position;
    }
 
 
    public long getItemId(int position) {
        return position;
    }
 
 
    public View getView(int position, View convertView, ViewGroup parent) {
        int view = getItemViewType(position);
        if (convertView == null) {
        	convertView = mInflater.inflate(R.layout.diff_view1, null);
        }
 
        ((ListView) convertView.findViewById(R.id.listView1)).setAdapter(adap[position]);
        return convertView;
    }
 
 
    /* (non-Javadoc)
	 * @see org.taptwo.android.widget.TitleProvider#getTitle(int)
	 */
	public String getTitle(int position) {
		return names[position];
	}
Cela m'affiche bien la un certain nombre de listview avec des objets différents comme je voulais, seul soucis : avec la méthode onItemClick l'événement que je spécifie ne se produit que pour les objets de la 1ère listview... Si je scroll horizontalement sur une autre listview rien ne se produit au clic.

Est-ce que quelqu'un voit se qu'il me manque pour que le onItemClick fonctionne sur toute mes listview, qui sont en faite les même, seul les objets dedans change, mais apparement le viewflow se comporte avec une position et la méthode onItemClick ne doit fonctionner que lorsque le viewflow est en position 0.

Merci.