Bonjour à tous et à toutes,
Je possède une vue ayant une liste. Dans chaque élément de ma liste, j'ai une checkbox.
Voici mon code:
detail_liste.xml:
liste_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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:textSize="20sp" android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5sp" /> <CheckBox android:layout_height="wrap_content" android:id="@+id/checkOK" android:layout_width="wrap_content" android:layout_gravity="right" android:layout_marginRight="10sp" /> </LinearLayout>
Dans mon activity:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" /> </LinearLayout>
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 ListView list = (ListView) findViewById(R.id.listview); ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map; map = new HashMap<String, String>(); map.put("text", "toto"); listItem.add(map); map = new HashMap<String, String>(); map.put("text", "tata"); listItem.add(map); SimpleAdapter mSchedule = new SimpleAdapter(this.getBaseContext(), listItem, R.layout.detail_liste, new String[] { "text" }, new int[] { R.id.text }); listZone.setAdapter(mSchedule);
Ma question est simple. J'aimerai pouvoir controler mes checkbox. C'est à dire savoir si elles sont cochées ou non, définir un événement onclick sur chacune d'entre elle.
Cependant, je n'ai aucune idée de comment les récupérer et comment définir un événement globale pour toutes les checkbox de ma liste.
Quelqu'un aurait une idée?
Faut il utiliser autre chose qu'une activity? listActivity ou autre? Dans ce cas comment faire?
EDIT: Après plusieurs recherche, j'ai vu qu'il était possible de redéfinir le SimpleAdapter afin de récupérer mes checkbox! Cependant, je n'ai aucune idée de comment faire
Merci d'avance![]()
Partager